gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 04:39:52 26 4
gpt4 key购买 nike

我想知道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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com