lrl1997 has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I'd like to do a regex match using perl.
Say I want to search strings containing more than 2 but not more than 3 of a range of characters "ARKYGZX", any letters can be repeats (i.e. AAA, RR, XXK etc) or scattered in the string (i.e. AgoodApeople, XgoodpeopleK, etc), so that as an example, the following strings should be print out as output:
AAgoodpeople
AgoodApeople
XgoodpeopleK
but "ARKYgoodpeopleGZX" shouldn't.
my code is as:
if ($_ =~ /[ARKYGZX]{2,3}/){ print $_, "\n"; }
But I think this only works if any of the character are repeats, such as "AAgoodpeople", for strings AgoodpeopleA", or "AXgoodpeople" or "AgoodpeopleX", this code wouldn't work.
Any suggestions?
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: match a range of characters multiple times but they might scattered in the string
by toolic (Bishop) on Feb 27, 2013 at 01:10 UTC | |
by AnomalousMonk (Archbishop) on Feb 27, 2013 at 01:23 UTC | |
|
Re: match a range of characters multiple times but they might scattered in the string
by AnomalousMonk (Archbishop) on Feb 27, 2013 at 01:03 UTC | |
|
Re: match a range of characters multiple times but they might scattered in the string
by 7stud (Deacon) on Feb 27, 2013 at 02:00 UTC |