regex - Splitting expression by regular expressions (PHP) -


i want split string: "33a/5" on parts "33", "a", "5".

is in php possibility write regex as: "/^(\d+) (\d) \/? (\d+)/", expressions in brackets ( exp ) become separate parts?

you can use preg_match this:

preg_match("/^(\d+) (\d+) \/? (\d+)/x", $text, $match); 

$match array separate matches.

the x modifier ignore spaces in regex; otherwise, don't put spaces:

preg_match("/^(\d+)(\d+)\/?(\d+)/", $text, $match); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -