Split a string in substring with regular expression
Posted: Sun Sep 29, 2013 11:53 am
This is my string:
Game: club 1 - Club2, Result: 4 - 2, Set: 2-1, 3-1, 2-1
I want to break these by a PHP preg_match in the next peaces:
- 1: club 1 - Club2
- 2: 4 - 2
- 3: 2-1
- 4: 3-1
- 5: 2-1
The length depends a little because it can be 3 sets but also 5 sets.
I have tried this:
$regex = "#Game: (.*)(\s\-\s)(.*),#"
I tried some more alternatives but it doesn't give the result what I like.
But that doesn't give me the result what I want.
Can somebody give me an idea how to get this result? It may also in three steps like:
1 step only: [0] Club 1 - Club 2
2 step result: [0] 4 -2
3 step set: [0] 2-1 [1] 3-1
Nico
Game: club 1 - Club2, Result: 4 - 2, Set: 2-1, 3-1, 2-1
I want to break these by a PHP preg_match in the next peaces:
- 1: club 1 - Club2
- 2: 4 - 2
- 3: 2-1
- 4: 3-1
- 5: 2-1
The length depends a little because it can be 3 sets but also 5 sets.
I have tried this:
$regex = "#Game: (.*)(\s\-\s)(.*),#"
I tried some more alternatives but it doesn't give the result what I like.
But that doesn't give me the result what I want.
Can somebody give me an idea how to get this result? It may also in three steps like:
1 step only: [0] Club 1 - Club 2
2 step result: [0] 4 -2
3 step set: [0] 2-1 [1] 3-1
Nico