We don't bite newbies here... much | |
PerlMonks |
Re: How to use a negative backreference in regex?by shmem (Chancellor) |
on Mar 02, 2009 at 23:03 UTC ( [id://747569]=note: print w/replies, xml ) | Need Help?? |
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$/ The following constructs such regexes. It takes a character sequence, and a file as input, and outputs the constructed pattern, then all the matching words in the file. Giving the characters numbers, these vertically aligned pairs match so the constructed regexp for character would be
Note that the back-references start with 2 because of the outer parens, which enclose $1 (or \1 inside the regexp).
Try match.pl fusselkerl /usr/share/dict/words. update: how would you specify a sequence to match a word composed of 15 different characters, which is 15 characters long? right: "dermatoglyphics". Or "1234567890abcde". ;-)
In Section
Seekers of Perl Wisdom
|
|