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 | |
by ikegami (Patriarch) on Oct 09, 2009 at 02:19 UTC |