Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: When a regexp with /g needs to be run .. twice

by toolic (Bishop)
on Mar 02, 2018 at 21:28 UTC ( #1210263=note: print w/replies, xml ) Need Help??


in reply to When a regexp with /g needs to be run .. twice

Your regex captures the colon into $1 and the left curly brace into $2 the first time through. The g modifier makes it attempt to capture 2 more characters AFTER the left curly brace, but there is only one character remaining (double quote), so the match fails. Just capture one matching character:
$foo =~ s/([:,{])/$1 /g;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1210263]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2021-12-05 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (31 votes). Check out past polls.

    Notices?