Results 1 to 2 of 2
Thread: preg_match for confusing string
Jun 16, 2007, 07:44 #1
- Join Date
- Mar 2007
- 0 Post(s)
- 0 Thread(s)
preg_match for confusing string
I really need some help with following string:
M1;, Bedfordshire, Flitwick, M1; 12, A5120;
What I ideally want is for the string to look like:
M1, Bedfordshire, Flitwick, M1 - Junction 12, A5120
So basically I need to match the string part: M1; 12 and turn it into M1 - Junction 12 and then match any remaining semi-colon and delete it.
Please help as I have spent a couple of days scratching my head on this one.
Jun 16, 2007, 08:52 #2Code php:
$s = 'M1;, Bedfordshire, Flitwick, M1; 12, A5120;'; $s = preg_replace('/([^;]+);, ([^,]+), ([^,]+), ([^;]+); ([^,]+), ([^;]+);/', '\\1, \\2, \\3, \\4 - Junction \\5, \\6', $s); # M1, Bedfordshire, Flitwick, M1 - Junction 12, A5120Logic without the fatal effects.
All code snippets are licensed under WTFPL.