File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -50,16 +50,25 @@ Submatches are also C<Match> objects (or lists of C<Match> objects,
50
50
if the corresponding regex was quantified), so each match object
51
51
can be seen as the root of a tree of match objects.
52
52
53
+ A C < Match > object can also hold the result of a match in progress
54
+ (while the grammar engine is running), in which case the C < pos > method
55
+ returns the current position. This view on C < Match > objects is only visible
56
+ if you call code from within a regex.
57
+
53
58
= head1 Methods
54
59
55
60
= head2 method pos
56
61
57
62
method pos()
58
63
59
- Returns the current position as a string index into C < Match.target > .
64
+ Returns the current position as a string index into C < Match.target > for a regex match
65
+ in progress:
66
+
67
+ my $a = 'abcdef';
68
+ $a ~~ /b. {say $/.pos }../; say $/.pos; # OUTPUT: «3»
60
69
61
- my $a = "þor" ~~ /o/;
62
- say $a.pos; # OUTPUT: «2»
70
+ You should not use this method on finished Match, as the output can be implementation
71
+ specific.
63
72
64
73
= head2 method target
65
74
@@ -80,7 +89,14 @@ Clones the C<Match> object.
80
89
81
90
= head2 method orig
82
91
83
- Returns the original string that the regex was matched against.
92
+ Returns the original input to the regex engine, which is usually a string,
93
+ but doesn't need to be (could be anything that can be coerced to a string):
94
+
95
+ 42 ~~ /.+/;
96
+ say $/.orig; # OUTPUT: «42»
97
+ say $/.orig.^name; # OUTPUT: «Int»
98
+
99
+ See L < #method target > for a close equivalent that always returns a string.
84
100
85
101
= head2 method from
86
102
You can’t perform that action at this time.
0 commit comments