简体   繁体   English

正则表达式匹配单词与值 PHP 前后的字符

[英]Regex match word with characters before and after the value PHP

I've been searching all day finding a regular expression that looks for a specific word even if there are signs in front or behind.我一整天都在寻找一个正则表达式,即使前面或后面有标志,也能查找特定单词。

It should be used for a bad words filter.它应该用于坏词过滤器。 It must look for exact matches but also with marks around the word它必须寻找精确匹配,但也必须在单词周围加上标记

It has to search through an array of bad words它必须搜索一系列坏词

For example:例如:

stupid - must match
123stupid - must match
stupid123 - must match
123stupid456 - must match
stupi - must not match (because the bad word is not fully inserted)

All I can find so far is looking only at whether the exact word (stupid but not 123stupid) or it also searches the half word (stupi)到目前为止我能找到的只是查看确切的单词(愚蠢但不是 123stupid)还是它也搜索半个单词(stupi)

Can anyone help me?谁能帮我?

你可以简单地使用

preg_match('/stupid/', $string)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM