Regexp to check for continuous 3 digits per line

I want the regular expression in java to be checked if the string contains continuous 3 digits. But the problem is that my string may contain unicode characters. If a string contains Unicode characters, it must skip Unicode characters (skip 4 'after and AND #) and perform validation. Some examples:

Neeraj : false Neeraj123 : true &#1234Neeraj : false &#1234Neeraj123 : true 123N&#123D : true Neeraj&#1234 : false Neeraj&#12DB123 : true &#1234 : false 
+4
source share
1 answer

You need to use a negative lookbehind statement :

 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 
+6
source

Source: https://habr.com/ru/post/1443789/


All Articles