regex - Perl 当前(5.8 和 5.10)是否对将使用的顺序交替做出任何 promise ?

标签 regex perl

给定像 /(foo|foobar|foobaz)/ 这样的交替,Perl 5.8 或 5.10 是否 promise 将首先使用这三个中的哪一个,如果它这样做,文档中的哪里做它兑现了 promise ?

参见相关问题Does Perl 6 make any promises about the order alternations will be used?

最佳答案

http://perldoc.perl.org/perlre.html#Combining-RE-Pieces :

if we match a regular expression a|ab against "abc" , will it match substring "a" or "ab" ? One way to describe which substring is actually matched is the concept of backtracking (see "Backtracking"). However, this description is too low-level and makes you think in terms of a particular implementation.

Another description starts with notions of "better"/"worse"

Again, for elementary pieces there is no such question, since at most one match at a given position is possible. This section describes the notion of better/worse for combining operators. In the description below S and T are regular subexpressions.

...

  • S|T

When S can match, it is a better match than when only T can match.

(在上下文中,只有当使用 S 的匹配至少与使用 T 的匹配一样早地匹​​配到字符串中时,才符合条件。)

关于regex - Perl 当前(5.8 和 5.10)是否对将使用的顺序交替做出任何 promise ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/766474/

相关文章:

c - 如何在 Perl 中运行外部程序?

php - 密码 PHP 的正则表达式

php - 简单正则表达式中同一行存在多个匹配的问题

regex - Notepad++ 中的搜索模式

perl - 在 perl 中重写递归函数,以便它可以在列表上下文中使用

perl - 如何从 Perl 读取 Gmail 帐户中的邮件?

perl - Perl:遍历文件并替换

java - 请解释*贪婪量词的工作原理

javascript - 正则表达式:\b 对于不以单词字符开头的字符串?

linux - Perl 在解析和打印文件段时正在更改和消除声明的变量?可能的错误?