I'm trying to find a regexp that exclude specific word but not words containing it.
For example if we exclude the word "home"
home --> NOT OK
homefree -> OK
freehome -> OK
Any ideas ?
Thanks
I would recommend taking a look at Rexegg — Word Boundaries .
If you want to match lines not containing "home" itself, you can do:
preg_match_all('/^(?!.*\bhome\b).*$/im', $str, $matches);
If you want to match the words alone:
preg_match_all('/\b(?!home\b)\w+/i', $str, $matches);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.