You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/Type/Match.pod6
+10-2Lines changed: 10 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -13,20 +13,28 @@ in the original string, and a payload referred to as I<AST> (abstract syntax
13
13
tree), which can be used to build data structures from complex regexes and
14
14
grammars.
15
15
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:
17
17
18
18
my $c;
19
19
'abc' ~~ /.$${ $c = $¢ }/;
20
20
say $c; # OUTPUT: «「c」»
21
21
22
22
In this case, we are running the code among curly braces when the match occurs,
23
23
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>
25
27
26
28
my $c; 'camelia' ~~ /<[ l m ]> {$c = $¢}/;
27
29
say $c; # OUTPUT: «「m」»
28
30
say $/; # OUTPUT: «「m」»
29
31
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
+
30
38
Submatches are also C<Match> objects (or lists of C<Match> objects,
31
39
if the corresponding regex was quantified), so each match object
32
40
can be seen as the root of a tree of match objects.
0 commit comments