The meaning of \1* operator in Java regexes
我正在学习JavaRexes,我注意到以下操作符:
1 | \\*1 |
我很难理解它的含义(在网上搜索没有帮助)。例如,这两个选项之间的区别是什么:
1 2 3 4 5 6 7 8 |
结果:
1 2 | a a |
谢谢!
在这种情况下,
所以在这种情况下,
下面是一个例子,说明了不同之处:
1 2 3 4 5 6 7 8 9 10 |
输出:
1 2 | aa a |
如您所见,当您有多个
1 2 3 | Pattern p1 = Pattern.compile("(a)\\1+"); Matcher m1 = p1.matcher("aaaaabbaaabbba"); while (m1.find()) System.out.println(m1.group()); |
输出将是:
aaaaa
aaa
但是最后一个
In Perl, \1 through \9 are always interpreted as back references; a backslash-escaped number greater than 9 is treated as a back reference if at least that many subexpressions exist, otherwise it is interpreted, if possible, as an octal escape. In this class octal escapes must always begin with a zero. In this class, \1 through \9 are always interpreted as back references, and a larger number is accepted as a back reference if at least that many subexpressions exist at that point in the regular expression, otherwise the parser will drop digits until the number is smaller or equal to the existing number of groups or it is one digit.
从模式文档。
因此,只要至少有一个