java - java.util.regex 包支持哪些标准

标签 java regex posix posix-ere

我想知道java支持哪些正则表达式标准。我所说的标准一词是指它是否支持 IEEE POSIX BRE、ERE 和 SRE。

任何人都可以提供任何想法吗?

提前感谢您的回复。

最佳答案

This document来自 Oracle 的文档包含有关 Java SE 7 中支持的正则表达式构造的大量信息,尽管它没有提及支持哪种标准:

Comparison to Perl 5

The Pattern engine performs traditional NFA-based matching with ordered alternation as occurs in Perl 5.

Perl constructs not supported by this class:

  • Predefined character classes (Unicode character)
    • \h A horizontal whitespace
    • \H A non horizontal whitespace
    • \v A vertical whitespace
    • \V A non vertical whitespace
    • \R Any Unicode linebreak sequence \u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029]
    • \X Match Unicode extended grapheme cluster
  • The backreference constructs, \g{n} for the nthcapturing group and \g{name} for named-capturing group.
  • The named character construct, \N{name} for a Unicode character by its name.
  • The conditional constructs (?(condition)X) and (?(condition)X|Y),
  • The embedded code constructs (?{code}) and (??{code}),
  • The embedded comment syntax (?#comment), and
  • The preprocessing operations \l, \u, \L, and \U.

Constructs supported by this class but not by Perl:

  • Character-class union and intersection as described above.

Notable differences from Perl:

  • 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.

  • Perl uses the g flag to request a match that resumes where the last match left off. This functionality is provided implicitly by the Matcher class: Repeated invocations of the find method will resume where the last match left off, unless the matcher is reset.

  • In Perl, embedded flags at the top level of an expression affect the whole expression. In this class, embedded flags always take effect at the point at which they appear, whether they are at the top level or within a group; in the latter case, flags are restored at the end of the group just as in Perl.

关于java - java.util.regex 包支持哪些标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16738955/

相关文章:

java - 无法调整 selenium grid 2 节点上的窗口大小

java - 使用哪种 Javax.awt 布局?

java - 这个 getGeneratedKeys() JDBC 语句有什么问题?

c - 如何测试调用进程是否是fork

c++ - 如何从 POSIX 文件描述符构造 c++ fstream?

java - 如何从 firebase 数据库中获取数据并将其保存 30 秒,然后获取另一条记录,直到最后一条记录?

JavaScript 正则表达式也可以匹配数字

regex - ctags 的多行正则表达式

regex - 在多种文件类型的查找命令中使用正则表达式

c++ - setLastModified 日期与 Qt