On 04/08/2011 03:12 AM, Anirban Adhikary wrote:
Can anybody please explaing the meaning of the following regular expression
my $x = '12abc34bf5';
@num = split /(a|b)+/, $x;
YAPE::Regex::Explain is great for this:
[pdurbin@beamish ~]$ perl -MYAPE::Regex::Explain -e 'print
YAPE::Regex::Explain->new("(a|b)+")->explain'
The regular expression:
(?-imsx:(a|b)+)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
( group and capture to \1 (1 or more times
(matching the most amount possible)):
----------------------------------------------------------------------
a 'a'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
b 'b'
----------------------------------------------------------------------
)+ end of \1 (NOTE: because you are using a
quantifier on this capture, only the LAST
repetition of the captured pattern will be
stored in \1)
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
[pdurbin@beamish ~]$
Phil
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/