regex - Split camelCase word into words with php preg_match (Regular Expression) -
how go splitting word:
onetwothreefour
into array can get:
one 2 3 4
with preg_match
?
i tired gives whole word
$words = preg_match("/[a-za-z]*(?:[a-z][a-za-z]*[a-z]|[a-z][a-za-z]*[a-z])[a-za-z]*\b/", $string, $matches)`;
you can use preg_match_all
as:
preg_match_all('/((?:^|[a-z])[a-z]+)/',$str,$matches);
explanation:
( - start of capturing parenthesis. (?: - start of non-capturing parenthesis. ^ - start anchor. | - alternation. [a-z] - 1 capital letter. ) - end of non-capturing parenthesis. [a-z]+ - 1 ore more lowercase letter. ) - end of capturing parenthesis.
Comments
Post a Comment