例如:
$s1 = "Test Test the rest of string"
$s2 = "Test the rest of string"
我想积极匹配$s1
但不是$s2
,因为第一个词$s1
与第二个相同。单词'Test'
例如,正则表达式应该适用于任何单词。
if(preg_match('/^(\w+)\s+\1\b/',$input)) {
// $input has same first two words.
}
解释:
^ : Start anchor
( : Start of capturing group
\w+ : A word
) : End of capturing group
\s+ : One or more whitespace
\1 : Back reference to the first word
\b : Word boundary
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)