Hello talexb,
From the end of perlop#Regexp-Quote-Like-Operators:
Occasionally, you can't use just a /g to get all the changes to occur that you might want. Here are two common cases:
# put commas in the right places in an integer 1 while s/(\d)(\d\d\d)(?!\d)/$1,$2/g; # expand tabs to 8-column spacing 1 while s/\t+/' ' x (length($&)*8 - length($`)%8)/e;
(Note that the /g modifier in the first example isn’t actually needed.) You can adapt this approach to your requirements:
my $foo = ':{,"'; 1 while $foo =~ s/([:,{])(?! )(.)/$1 $2/; print ">$foo<\n";
Output:
19:22 >perl 1872_SoPW.pl >: { , "< 19:22 >
Hope that’s of interest,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: When a regexp with /g needs to be run .. twice
by Athanasius
in thread When a regexp with /g needs to be run .. twice
by talexb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |