我想要java中的正则表达式来检查字符串是否包含连续的3位数字。但问题是我的字符串可能包含 unicode 字符。如果字符串包含 unicode 字符,则应跳过 unicode 字符(跳过 & AND # 之后的 4 '.)并进行检查。一些例子是
Neeraj : false
Neeraj123 : true
ӒNeeraj : false
ӒNeeraj123 : true
123N{D : true
NeerajӒ : false
NeerajDB123 : true
Ӓ : false
你需要使用负数后向断言 http://www.regular-expressions.info/lookaround.html:
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);
您可以按如下方式使用它:
Matcher regexMatcher = regex.matcher(subjectString);
return regexMatcher.find(); // returns True if regex matches, else False
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)