I have been trying to convert a regular expression from ruby to PHP, however I have had little luck.
This is the ruby regular expression:
QUOTED_LITERAL = /"[^"\\]*(?:\\.[^"\\]*)*"/
UNQUOTED_LITERAL = /[^\s=,][^\s=,\\]*(?:\\.[^\s=,\\]*|=[^,>])*/
LITERAL = /(#{QUOTED_LITERAL}|#{UNQUOTED_LITERAL})/
PAIR = /#{LITERAL}\s*=>\s*#{LITERAL}/
And this is my go in PHP:
const PAIR = '/("[^"\\]*(?:\\.[^"\\]*)*"|[^\s=,][^\s=,\\]*(?:\\.[^\s=,\\]*|=[^,>])*)\s*=>\s*("[^"\\]*(?:\\.[^"\\]*)*"|[^\s=,][^\s=,\\]*(?:\\.[^\s=,\\]*|=[^,>])*)/';
However when I run
$result = preg_match_all(self::PAIR, $input, $matches);
I get the error:
preg_match_all(): Compilation failed: unmatched parentheses at offset 62
However when run it through, http://www.phpliveregex.com/ with the test data:
"foo" => "bar", "foo" => bar, foo => "bar"
it seems to work fine.
Not sure whats going on.