in reply to Re^4: Regex for matching n-fold repititions of arbitrary characters
in thread Regex for matching n-fold repititions of arbitrary characters

/pat/g means /(pat)/g if pat contains no captures. In list context, m// returns what it captured (or 1 if there are no captures) on success.

$ perl -wle'print for "aabbaab" =~ /((.)\2+)/sg;' aa a bb b aa a
$ perl -wle'print $1 while "aabbaab" =~ /((.)\2+)/sg;' aa bb aa

Note that if "aabbaab" =~ /aa|bb/g is wrong. Red flags should be raised when you see /g in scalar context outside a loop.

Replies are listed 'Best First'.
Re^6: Regex for matching n-fold repititions of arbitrary characters
by LanX (Saint) on Oct 08, 2009 at 21:39 UTC
    Note that if "aabbaab" =~ /aa|bb/g is wrong. Red flags should be raised when you see /g in scalar context outside a loop.

    Not necessarily! It makes sense when parsing with nested ifs! Friedl's book has some nifty examples...

    Cheers Rolf

      I didn't say m//g in scalar context outside a loop is wrong. I said it's usually wrong. I said the code he used was wrong.

      And I bet his tokenizers used /c too