只是好奇地想知道。我注意到我的regexp在与"\b"一起使用时找不到字符串"C#"
if (preg_match('@bC#b@i', $userSkills)) {...
但是,如果我删除"\b",它会设法找到字符串。
有人知道这里可能出了什么问题吗?
查找匹配项的字符串:
Unified Communications Design Specialist ~$~ Windows 95 or 98 ~$~ Windows 2000
or XP ~$~ Linux ~$~ Visual Basic ~$~ ASP Net ~$~ C# ~$~ Contact Center Design
Specialist ~$~ Internet Programming ~$~ Object oriented programming ~$~
Databases ~$~ Unified Commucations ~$~ Contact Center Solutions ~$~
Junior Developer ~$~ Solutions Engineer
对于单词边界,转义序列是b
而不是/b
。
if (preg_match('@bC#b@i', $userSkills)) {...
这是因为#
不是单词字符。我在你的字符串中用|:标记了"C#
"周围的单词边界
|ASP| |Net| ~$~ |C|# ~$~ |Contact|
您可以看到,在"#
"one_answers""之间没有边界,因此CCD_7不匹配。