Reputation: 11448
Example input:
hjkhwe5boijdfg
I need to split this into 3 variables as below:
I've got the PHP preg_match
all setup but have no idea how to do this complex regex. Could someone give me a hand?
Upvotes: 3
Views: 165
Reputation: 91385
Have a try with:
$str = 'hjkhwe5boijdfg';
preg_match("/^([a-z]+\d+)([a-z])(.*)$/", $str, $m);
print_r($m);
output:
Array
(
[0] => hjkhwe5boijdfg
[1] => hjkhwe5
[2] => b
[3] => oijdfg
)
Explanation:
^ : begining of line
( : 1rst group
[a-z]+ : 1 or more letters
\d+ : followed by 1 or more digit
) : end of group 1
( : 2nd group
[a-z] : 1 letter
) : end group 2
( : 3rd group
.* : any number of any char
) : end group 3
$
Upvotes: 1