[tpm] New Regex question - partially solved

Rob Janes janes.rob at gmail.com
Sun Oct 28 04:02:44 PDT 2012


Uri, my apologies, you did say use $1 in the replacement side and I missed
that.  yes, agreed, use $1 on the replacement side, \1 on the match side.

On Sun, Oct 28, 2012 at 6:45 AM, Rob Janes <janes.rob at gmail.com> wrote:

> 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/4b7e0a3f/attachment.html>


More information about the toronto-pm mailing list