RegEx in php for "comma, space or one line"?

I have a textarea field in my webpage. I accept user input, I want to parse this user input for "(SEPARATE BY COMPASS, SPACES OR ONE PER LINE)" this line.

Basically, I want to get words separated by comma, space or one per line. What can be RegEx for this, what can I use as below:

preg_split('/[,; " "]+/', $_tags);

      

I am already using regEx to separate user-entered tags. What would be the regEx to extract a word from a string that is "(SEPARATELY COMPASSES, SPACES OR ONE PER LINE)"

thank

+2


source to share


2 answers


<?php  
$_tags = "foo bar, dim; sum\nblah";
var_dump(preg_split('/[;, \n]+/', $_tags));
?>

      

Results:



array(5) {
  [0]=>
  string(3) "foo"
  [1]=>
  string(3) "bar"
  [2]=>
  string(3) "dim"
  [3]=>
  string(3) "sum"
  [4]=>
  string(4) "blah"
}

      

+7


source


preg_split('/[,;\ \n]+/', $_tags);

      

or when using php> 5.2.4

preg_split('/[,;\ \v]+/', $_tags);

      



or

preg_split('/[,;\s]+/', $_tags);

      

+4


source







All Articles