How to make preg_match to find whole word but not separate hyphen-words?

前端 未结 1 1894
不思量自难忘°
不思量自难忘° 2021-01-24 02:00
if (preg_match(\'#\\b\'.$rawword.\'\\b#i\',$body)) {   

This code finds whole words, but if they are a hyphen word like \"ABLE-BODIED\" it will find AB

相关标签:
1条回答
  • 2021-01-24 02:34

    You can use lookbehind and lookahead operators. This operators looks in behind and after but not match them.

    for example use \b(?<!-)xyz(?!-)\b for finding whole words of xyz that doesn't have - before or after.

    0 讨论(0)
提交回复
热议问题