[tpm] New Regex question - partially solved
Uri Guttman
uri at stemsystems.com
Sun Oct 28 09:02:49 PDT 2012
On 10/28/2012 06:45 AM, Rob Janes wrote:
> ok, if you don't believe me when I say it doesn't work, try it yourself
> then.
>
i haven't tried it as i said i didn't test it.
> [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.
>
please read the docs. you are greatly mistaken about \1 and $1. you keep
using \1 in the replacement where it doesn't belong. why it seems to
work is another story. when i get to playing with the code i will figure
it out. too busy today.
and learn to bottom post too.
uri
More information about the toronto-pm
mailing list