[tpm] New Regex question - partially solved
Rob Janes
janes.rob at gmail.com
Sun Oct 28 03:45:35 PDT 2012
ok, if you don't believe me when I say it doesn't work, try it yourself
then.
[robj at rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print "$x\n"; $x =~
s/(\s)$1+/\1/; print "$x\n";'
one two
one two
[robj at rj-ul80vt ~]$ perl -e '$x = "one \t\t two"; print "$x\n"; $x =~
s/(\s)\1+/\1/; print "$x\n";'
one two
one two
notice that the usage of $1 resulted in a mixed string of whitespace being
substituted. only the tabs should have been substituted, not everything.
therefore, the $1 in the matching regex resolved to \s not space.
On Sat, Oct 27, 2012 at 11:52 PM, Uri Guttman <uri at stemsystems.com> wrote:
> On 10/27/2012 07:42 PM, Rob Janes wrote:
>
>> Slurp the file and run the second regex.
>>
>> undef $/;
>> $exp = <in>;
>>
> use File::Slurp is much better for that.
>
>
> $exp =~ s/(\s)\1+/\1/g;
>>
>
> i keep saying to not use \1 in the replacement. it is documented to be
> wrong but supported. don't use it there. use $1
>
> uri
>
> ______________________________**_________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/**listinfo/toronto-pm<http://mail.pm.org/mailman/listinfo/toronto-pm>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20121028/a78bfb29/attachment.html>
More information about the toronto-pm
mailing list