in reply to A Quick Regex Question
One way to do it is to use tr to count the characters of interest in each word:
use strict; use warnings; my @words = qw(Perl purile pretty reputation reputable); for (@words) { print "Matched $_\n" if tr/pP// && tr/eE// && tr/rR// && tr/lL//; }
Prints:
Matched Perl Matched purile Matched reputable
Note that you have to test seperately for each letter and ensure that at least one of each is present. That is why there are four different tests - one for each letter.
Note too that if you want a case insensitive match both upper and lower case versions of the letter need to be present.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A Quick Regex Question
by eyepopslikeamosquito (Archbishop) on Oct 08, 2006 at 09:00 UTC | |
by GrandFather (Saint) on Oct 08, 2006 at 09:19 UTC | |
|
Re^2: A Quick Regex Question
by chinamox (Scribe) on Oct 09, 2006 at 09:01 UTC |