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?