perl6正则 5: [ ] / | / ||

 

也就是可以把多种要匹配的写进[ ] 中, 第种用 | 分开就行了。

| 与 || 有差别

|的话, 当匹配位置 相同时, 会取最长的, 而 || , 当前面的匹配成功, 后面的就不会再去匹配。

 

 

/
/
/
/
/
/
/
a || bc /
# matches 'a' or 'bc'
( a || b ) c / # matches 'ac' or 'bc'
[ a || b ] c / # Same: matches 'ac' or 'bc', non-capturing grouping
a b+ /
# Matches an 'a' followed by one or more 'b's
(a b)+ /
# Matches one or more sequences of 'ab'
[a b]+ /
# Matches one or more sequences of 'ab', non-capturing
(a || b)+ /
# Matches a sequence of 'a's and 'b's(at least one)

 注意 [] 跟 <[]> 是不同的:

原文地址:https://www.cnblogs.com/perl6/p/7500066.html