PHP如何使用regEX将数字和字符串分隔为'space-space'

Please I have the flowing string :

$str = 'blabla-blabla - 12345, blobl-ooo - 54123, hihihi - 98745'; 

I want to get in an array blabla-blabla - 12345 and blobl-ooo - 54123 and hihihi - 98745

To do that I'm thinking to use REGEXP so I've tried :

preg_match_all("/\b[\p{L}'-]+|[a-z]+\b/u", $str, $all); 

but this get only the string part and not the numbers.

Please any advice masters ?

PS : I can't use list and explode because I don't know the number of elements in my string.

For your regex, try:

preg_match_all('/([\w\-]+ \- \d+),?/u', $str, $all);

\w deals for all letters or digits, and the \d for all digits.

Otherwise, even if you do not know the size of your string, you can use explode:

$parts = explode(', ', $str);
foreach($parts as $part) {
    // ...
}

I'm not sure why you can't use explode to split on commas. You don't need to know the number of elements to do that. However, a regex like this should work:

"/[\w\-]+ \- \d+/"

You can use preg_split function for it..

str = 'blabla-blabla - 12345, blobl-ooo - 54123, hihihi - 98745'; 
$result=preg_split('/,/',$str);
echo "<pre>";
print_r($result);

Output Array ( [0] => blabla-blabla - 12345 1 => blobl-ooo - 54123 2 => hihihi - 98745 )

DEMO