这必须仅匹配这些数字:110、220、330、440、550、660、770、880、990
(不包括 000)。这个正则表达式 (pcre) 有更短的方法吗?
/^(1{2}|2{2}|3{2}|4{2}|5{2}|6{2}|7{2}|8{2}|9{2})0$/
最佳答案
您可以使用:
/\b([1-9])\g{1}0\b/
正则表达式的分解:
\b # word boundary
[1-9] # match digit 1-9 and group them as captured group #1
\g{1} # back-reference to group #1
0 # match 0
\b # word boundary
关于php - 正则表达式的较短方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30592472/