Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: match a range of characters multiple times but they might scattered in the string

by AnomalousMonk (Abbot)
on Feb 27, 2013 at 01:03 UTC ( #1020789=note: print w/ replies, xml ) Need Help??


in reply to match a range of characters multiple times but they might scattered in the string

>perl -wMstrict -le "my $range = quotemeta 'ARKYGZX'; ;; my $rng = qr{ [$range] }xms; my $not_rng = qr{ [^$range] }xms; ;; for my $s (qw( AAA RR XXK AxA xAxxYxxRx A xAx ARKYGZX XxZxGxYxKxRxA AxAxAxA xYYYYx xRRRRRx RRRR )) { my $match = $s =~ m{ \A $not_rng* $rng (?: $not_rng* $rng){1,2} $not_rng* \z }xms; printf qq{%s match : '%s' \n}, $match ? ' ' : 'NO', $s; } " match : 'AAA' match : 'RR' match : 'XXK' match : 'AxA' match : 'xAxxYxxRx' NO match : 'A' NO match : 'xAx' NO match : 'ARKYGZX' NO match : 'XxZxGxYxKxRxA' NO match : 'AxAxAxA' NO match : 'xYYYYx' NO match : 'xRRRRRx' NO match : 'RRRR'

Update: Apply quotemeta directly to  $range initialization, don't use  \Q \E


Comment on Re: match a range of characters multiple times but they might scattered in the string
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020789]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-12-28 00:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls