给定像 /(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/