how to remove Arabic hashtags?

Viewed 735

I am polling tweets from twitter using Twitter4j and I am trying to filter hashtags from it after I take text from it I turn it into strings now I have this String: "892698363371638784:RT @hikids_ksa: اللعبة خطيرة مرا ويبي لها مخ و تفكير و مهارة متوفرة في #متجر_هاي_كيدز_الالكتروني .."

I want to remove متجر_هاي_كيدز_الالكتروني as it has Hashtag after it using java

the problem my code didn't work on this input: "@kaskasomar هيدا بلا مخ متل متل غيرو بيخون الشعب اللبناني وبيتهمو بالارهاب بس لان رأيو بيختلف عن رأي الاخرين #سخيف"

the part سخيف wasn't removed for some reason this is my method

static String removeHashtags(String in)
{
    in = in.replaceAll("#[A-Za-z]+","");//remove English hashtags
    in = in.replaceAll("[أ-ي]#+","");//remove Arabic hashtags that have # before it
    return in = in.replaceAll("#[أ-ي]+","");//remove Arabic hashtags that have # after it
}
3 Answers

The code below removes Arabic hashtags mixed with English characters and [0-9] using the Unicode

import re
text = "#مرحبا"
reg = r"#[0-9\u0621-\u063A\u0640-\u066C\u0671-\u0674a-zA-Z_]+"
text = re.sub(reg, " ", text)

Example: regexr.com/691cn

Related