Reputation: 11
How to write regular expressions for the below-mentioned use cases?
I need two separate regexes as I need to perform logic based on that.
This will be used in Java
Tried (\u0660-\u0669) and [\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc] to check for Arabic character but does not work.
Upvotes: 1
Views: 247
Reputation: 627343
Using Matcher#find()
, you may match the strings with
String arabic_letter = "[\\p{InArabic}&&\\p{L}]";
String arabic_digit = "[\\p{InArabic}&&\\p{N}]";
Example:
Pattern p = Pattern.compile(arabic_letter);
Matcher m = p.matcher(your_string);
if (m.find()) {
// the string contains an Arabic letter
}
You may also use the regex in String#matches
with a slight modification:
s.matches("(?s).*[\\p{InArabic}&&\\p{L}].*")
s.matches("(?s)[^\\p{InArabic}&&\\p{L}]*[\\p{InArabic}&&\\p{L}].*")
Upvotes: 2