Java正则表达式1 = 1
问题描述:
我需要查找java regex模式,它找到格式为1 = 1的输入字符串,其中=前缀应该具有相同的后缀数字。这里还有前缀&后缀值应该相同,如1 = 1,11 = 11,223 = 223。 1 = 2,3 = 22,33 = 22之类的值不应与模式匹配
I need to look for java regex pattern that finds input string in the format of 1=1 where prefix of "=" should have same count of digits with the suffix. Also here both prefix & suffix values should be the same like 1=1, 11=11, 223=223. Values like 1=2, 3=22, 33=22 should not match the pattern
我们是否可以使用一般模式来满足上述规则。
Can we have a general pattern to satisfy above rules.
答
使用后退参考:
(\d+)=\1\b
当然,在java中你需要逃避回来斜杠:
of course, in java you need to escape the back slashes:
"(\\d+)=\\1\\b"