Reputation: 232
I'm looking for a RegEx for preg_replace in PHP for the following scenario:
"Bjerre- Jonas, Jorgensen- Silas, Wohlert- Johan, Madsen- Bo"
"Jonas Bjerre, Silas Jorgensen, Johan Wohlert, Bo Madsen"
-
to match on separating matches to be swappedI'm a noob at PHP and RegEx and have been playing around in the cool test arena with things like preg_replace("/^\"(?<=- )/", ""$2 $1$3"", $input_lines);
with horrible results. Thanks for help!
Upvotes: 0
Views: 267
Reputation: 67968
([^," -]*)\s*-\s*([^," ]*)
Try this.See demo.
http://regex101.com/r/hI0qP0/20
$re = "/([^\", -]*)\\s*-\\s*([^,\" ]*)/m";
$str = "\"Bjerre- Jonas, Jorgensen- Silas, Wohlert- Johan, Madsen- Bo\"";
$subst = "$2 $1";
$result = preg_replace($re, $subst, $str);
Upvotes: 1