Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. Array (
  2. [0] => word
  3. [1] => word
  4. [2] => dr
  5. [3] => word
  6. [4] => a.sh
  7. [5] => word
  8. [6] => a.k
  9. [7] => word )
  10.  
  11. $special_words = array("dr.", "a.sh.", "a.k");
  12. array_walk($special_words, function(&$item, $key){ $item= preg_quote($item, '~');});
  13.  
  14. $regex = '~(?<!w)(' . implode('|', $special_words) . '|w+)(?!w)~';
  15. $str = 'word word, dr. word: a.sh. word a.k word?!..';
  16. preg_match_all($regex, $str, $matches);
  17. var_dump($matches[0]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement