Skip to content

Commit fc50ce3

Browse files
committed
Adds information on versions closes #1760 again
1 parent b94f678 commit fc50ce3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

doc/Type/Match.pod6

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,28 @@ in the original string, and a payload referred to as I<AST> (abstract syntax
1313
tree), which can be used to build data structures from complex regexes and
1414
grammars.
1515
16-
The last match is also stored in the X<C<>> variable:
16+
The last match is also stored in the X<C<>> C<Match> object:
1717
1818
my $c;
1919
'abc' ~~ /.$${ $c = $¢ }/;
2020
say $c; # OUTPUT: «「c」␤»
2121
2222
In this case, we are running the code among curly braces when the match occurs,
2323
in this case the last letter in the string; C<$c> gets the value of the cursor
24-
C<>, which contains the C<Match>. 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<C<$/>|/syntax/$$SOLIDUS>
24+
C<>, which contains the C<Match>. This C<> offers a way of capturing the
25+
Match inside a regular expression; if you are not going to use it inside that
26+
you can simply use L<C<$/>|/syntax/$$SOLIDUS>
2527
2628
my $c; 'camelia' ~~ /<[ l m ]> {$c = $¢}/;
2729
say $c; # OUTPUT: «「m」␤»
2830
say $/; # OUTPUT: «「m」␤»
2931
32+
B<Note>: This feature works only from Perl 6 version 2018.02. It would have
33+
returned C<Nil> with any previous version. Alternatively and prior to that
34+
version, you could use C<$/> which, inside the regex, has the same value:
35+
36+
m: '123' ~~ / (\d) { say $0; say $/; } \d+ /; # OUTPUT: «「1」␤「1」␤ 0 => 「1」␤»
37+
3038
Submatches are also C<Match> objects (or lists of C<Match> objects,
3139
if the corresponding regex was quantified), so each match object
3240
can be seen as the root of a tree of match objects.

0 commit comments

Comments
 (0)