Regex与PHP空白的区别


regex difference with php whitespace

我不能让这个正则表达式与PHP工作,特别是中间的空白,值或单位匹配组单独匹配。

正则表达式:

/(?<value>'d+'.?'d*)('p{Z}|'s)(?<unit>(meters|mm))/

要解析的字符串:

Cord Length:1.52 meters

试试http://www.phpliveregex.com/它不匹配。

http://www.phpliveregex.com/p/bV7

试试https://regex101.com/就行了

编辑:似乎仍然没有在phpliveregex.com为我工作

http://www.phpliveregex.com/p/bV7

EDIT2:我已经编辑了要解析的字符串

除了上面的注释,我将修改你的正则表达式如下:

(?<value>'d+(?:'.'d+)?)'h+(?<unit>(?:meters|mm))