September 2017
Beginner
402 pages
9h 52m
English
Capturing becomes trickier when a regex has more than one or two capturing groups and if there are alternatives in a regex. For example, consider the following regex:
my $re = rx/ (<[a..z]>+) || (<[A..Z]>) (\d) /;
It contains two alternatives, but the number of capturing groups is different in each branch. (alternation is described in detail in the next section.)
Now, supply the strings that match with either the <[a..z]+> or <[A..Z]>\d regex:
'letter' ~~ $re;'A5' ~~ $re;
After the first matching, only $0 will be defined. Printing $1 will give Nil. In the second example, both variables will contain a value. It is also not easy to deduce, which part of the regex matched in each case. The straightforward way of checking how many ...
Read now
Unlock full access