PHP preg_match any character except word [duplicate]

一世执手 提交于 2019-12-05 17:44:15

The linked possible duplicate is about matching a row that does not contain a specified word. I am not sure if it is, what is asked here.

If you want to match everything in a string but not the specified word you have to use the anchor \b word boundary instead of ^ start of a string and $ end of a string.

For example

\b(?:(?!your).)+\b

to match everything except the word "your"

See it here on Regexr

(?!your) is a negative lookahead assertion that is true, if the string "your" is not following the current position.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!