in reply to When a regexp with /g needs to be run .. twice
$foo = ':{"' $foo =~ s/([:,{])(.)/$1 $2/g;
The first match of the regex matches :{, and then the regex engine continues looking after that match, but the only thing there is ", which does not match your regex, which expects two characters.
This works (although not yet tested on a lot of different inputs): s/(?<=[:,{])(?=.)/ /g (using Zero-Width Lookaround Assertions)
occurrences of left square bracket, colon and left brace
Left square brackets, or commas? You've got [:,{]
Of course, if you're cleaning up JSON, it might be better to just round trip it through a module that can pretty-print it?
|
|---|