我想了解Java将如何解释
(one)(one)(one)(one)(one)(one)(one)(one)(one)(one)(two)\11
它会尝试匹配第一组和末尾的文字 1
还是会尝试匹配第 11 组?怎么匹配到第11组?
最佳答案
Java 正则表达式为:
"(one)(one)(one)(one)(one)(one)(one)(one)(one)(one)(two)\\11"
它将匹配第 11 个捕获的组。
根据 Javadoc:
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.
关于具有 10 多个组的 Java 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32210668/