larryk has asked for the wisdom of the Perl Monks concerning the following question:
If I want to match a four letter word that starts and ends with the same character, I use: "test" =~ /^(.)..\1$/ - this is successful.
Now I want to match a four letter word that does not start and finish with the same letter, using: "test" =~ /^(.)..[^\1]$/ - this doesn't work; it's still a successful match.
It seems the backreference \1 is turning into an escaped literal within the character class.
P.S. ultimately, I'm trying to create a pattern that is able to say, "at some character position there either is or is not one of the preceeding characters," e.g."test" =~ /^(.)([^\1])([^\1\2])\1$/
larryk perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to use a negative backreference in regex?
by zwon (Abbot) on Feb 28, 2009 at 12:57 UTC | |
by gone2015 (Deacon) on Feb 28, 2009 at 13:36 UTC | |
by larryk (Friar) on Mar 02, 2009 at 22:01 UTC | |
Re: How to use a negative backreference in regex?
by missingthepoint (Friar) on Feb 28, 2009 at 13:03 UTC | |
Re: How to use a negative backreference in regex?
by johngg (Canon) on Feb 28, 2009 at 13:06 UTC | |
Re: How to use a negative backreference in regex?
by jettero (Monsignor) on Feb 28, 2009 at 13:18 UTC | |
Re: How to use a negative backreference in regex?
by shmem (Chancellor) on Mar 02, 2009 at 23:03 UTC |
Back to
Seekers of Perl Wisdom