I\'m trying to run a regexp in php (preg_match_all
) that matches certain whole words in a string, but problem is that it also matches words that contain only pa
If you really want to make sure you only get your words and not words that contain them, then you can use word boundary anchors:
/\b(testable|string)\b/
This will match only a word boundary followed by either testable
or string
and then another word boundary.
You don't want a character class with []
, you just want to match the words:
/testable|string/