php separating words by using regex -


i have string , contains words want reach, seperators can string consist of , ; or space.

here example:

;,osman,ali;, mehmet ;ahmet,ayse; , 

i need take words osman ali mehmet ahmet , ayse array or type can use them 1 one. tried using preg function couldn't figure out.

if help, appreciative.

$words = preg_split('/[,;\s]+/', $str, -1, preg_split_no_empty); 
  • [,;\s] character group means match of characters contained in group.
  • \s matches white space character (space, tab, newline, etc.). if replace space: [,; ].
  • + means match 1 or more of preceding symbol or group.

demo

http://www.regular-expressions.info/ site learn regular expressions.


Comments