具有 10 多个组的 Java 正则表达式

标签 java regex

我想了解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/

相关文章:

java - JVM-详细: Formatting out put

java - Jackson 来自 kotlin 的自定义 json 序列化 java 原语

java - 使用 Hibernate 连接不同数据库中的 2 个表

java - RED5 AXIS 相机捕捉和流媒体

regex - 在 Swift 中查找括号之间的文本

java - 如何从 Java 编写的文件中读取 C 语言的数据(二进制或文本)?

regex - 如何在 Linux 命令行中 grep 以双正斜杠开头的行?

c++ - regex_token_iterator 和 regex_iterator 有什么区别?

java - 以#@开头的字符串模式,可以包含下划线和减号

regex - Dart 说 Regexp 有无效的量词,但它在 JavaScript 中有效 - 一个错误?