Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Regex for matching n-fold repititions of arbitrary characters

by ikegami (Patriarch)
on Oct 08, 2009 at 18:59 UTC ( [id://800067]=note: print w/replies, xml ) Need Help??


in reply to Regex for matching n-fold repititions of arbitrary characters

backreferences
/(.)\1\1/s

Replies are listed 'Best First'.
Re^2: Regex for matching n-fold repititions of arbitrary characters
by pat_mc (Pilgrim) on Oct 08, 2009 at 19:15 UTC
    Thanks, ikegami ... I knew there should be an easy way to do it ... but had not used backreferences in regexes before.

    One follow-up to your post: Is the s modifier really required?

    Thanks again!

    Pat
      Depends on what you want /./ to match. If you want to match repetitions of any character, yes. If you want to match repetitions of specific characters, no, since you won't be using /./.
        Hm ... I follow you so far, ikegami ... but why do I get different output in the following two cases:
        ~$ perl -le 'print $& if "aabbaab" =~ /aa|bb/g' ~$ perl -le 'print join "\n", ( "aabbaab" =~ /aa|bb/g )' aa bb aa ~$ perl -le 'print join "\n", ( "aabbaab" =~ /(.)\1/g )' a b a

        The first two system responses are clear ... but why does the last regex using backreferences return only single characters?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 23:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found