diff --git a/doc/Type/Match.pod6 b/doc/Type/Match.pod6 index 05c2e7d94..814380e10 100644 --- a/doc/Type/Match.pod6 +++ b/doc/Type/Match.pod6 @@ -13,6 +13,20 @@ in the original string, and a payload referred to as I (abstract syntax tree), which can be used to build data structures from complex regexes and grammars. +The last match is also stored in the X> variable: + + my $c; + 'abc' ~~ /.$${ $c = $¢ }/; + say $c; # OUTPUT: «「c」␤» + +In this case, we are running the code among curly braces when the match occurs, +in this case the last letter in the string; C<$c> gets the value of the cursor +C<$¢>, which contains the C. This C<$¢> offers a way of capturing the Match inside a regular expression; if you are not going to use it inside that you can simply use L|/syntax/$$SOLIDUS> + + my $c; 'camelia' ~~ /<[ l m ]> {$c = $¢}/; + say $c; # OUTPUT: «「m」␤» + say $/; # OUTPUT: «「m」␤» + Submatches are also C objects (or lists of C objects, if the corresponding regex was quantified), so each match object can be seen as the root of a tree of match objects.