I want a regular expression in java to check, if a string contains continuous 3 digits. But the problem is my string may contain unicode characters. If the string contains unicode characters it should skip the unicode characters (skip 4 '.'s after & AND #) and should do the checking. Some examples are
Neeraj : false
Neeraj123 : true
ӒNeeraj : false
ӒNeeraj123 : true
123N{D : true
NeerajӒ : false
NeerajDB123 : true
Ӓ : false
You need to use a negative lookbehind assertion:
Pattern regex = Pattern.compile(
"(?<! # Make sure there is no... \n" +
" &\\# # &#, followed by \n" +
" [0-9A-F]{0,3} # zero to three hex digits \n" +
") # right before the current position. \n" +
"\\d{3} # Only then match three digits.",
Pattern.COMMENTS);
You can use it as follows:
Matcher regexMatcher = regex.matcher(subjectString);
return regexMatcher.find(); // returns True if regex matches, else False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With