Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array (
- [0] => word
- [1] => word
- [2] => dr
- [3] => word
- [4] => a.sh
- [5] => word
- [6] => a.k
- [7] => word )
- $special_words = array("dr.", "a.sh.", "a.k");
- array_walk($special_words, function(&$item, $key){ $item= preg_quote($item, '~');});
- $regex = '~(?<!w)(' . implode('|', $special_words) . '|w+)(?!w)~';
- $str = 'word word, dr. word: a.sh. word a.k word?!..';
- preg_match_all($regex, $str, $matches);
- var_dump($matches[0]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement