【发布时间】:2018-04-27 23:39:26
【问题描述】:
我需要找到一种方法在文本中找到部分字符串并将其替换为 ***
例如,我有文字"Jumping fox jumps around the box"
在正常情况下,我会使用:
preg_replace('/\b(fox)\b/i', '****', "fox");
但是当我们有文本"Jumping f.o.x jumps around the box" 时,我想涵盖案例
或"Jumping f o x jumps around the box"
所以基本上,我需要正则表达式来支持这种搜索...覆盖更多特殊字符会更好
【问题讨论】:
-
然后使用
'/\bf\W*o\W*x\b/i'
标签: php regex laravel preg-replace preg-match