@@ -166,7 +166,58 @@ Examples:
166
166
167
167
method match($pat, :continue(:$c), :pos(:$p), :global(:$g), :overlap(:$ov), :exhaustive(:$ex), :st(:$nd), :rd(:$th), :$nth, :$x --> Match)
168
168
169
- TODO
169
+ Performs a match of the string aginst C < $pat > and returns a L < Match > object if there is a successful match,
170
+ and C < (Any) > otherwise. Matches are stored in C < $/ > . If C < $pat > is not a L < Regex > object, match will coerce
171
+ the argument to a Str and then perform a literal match against C < $pat > .
172
+
173
+ A number of optional named parameters can be specified, which alter how the match is performed.
174
+
175
+ = item :continue
176
+
177
+ The :continue adverb takes as an argument the position where the regex should start to search.
178
+ If no position is specified for :c it will default to 0 unless $/ is set, in which case it defaults to $/.to.
179
+
180
+ = item :pos
181
+
182
+ Takes a position as an argument. Fails if regex cannot be matched from that postion, unlike :continue.
183
+
184
+ = item :global
185
+
186
+ Instead of searching for just one match and returning a Match object, search for every non-overlapping match and return them in a List.
187
+
188
+ = item :overlap
189
+
190
+ Finds all matches including overlapping matches, but only returns one match from each starting position.
191
+
192
+ = item :exhaustive
193
+
194
+ Finds all possible matches of a regex, including overlapping matches and matches that start at the same position.
195
+
196
+ = item :st, :nd, rd, nth
197
+
198
+ Takes an integer as an argument and returns the nth match in the string.
199
+
200
+ = item :x
201
+
202
+ Takes as an argument the number of matches to return, stopping once the specified number of matches has been reached.
203
+
204
+ Examples:
205
+ = begin code
206
+
207
+ "properly".match('perl'); # 「perl」
208
+ "properly".match(/p.../); # 「perl」
209
+ "1 2 3".match([1,2,3]); # 「1 2 3」
210
+ "a1xa2".match(/a./, :continue(2)) #「a2」
211
+ "abracadabra".match(/ a .* a /, :exhaustive); #(「abracadabra」 「abracada」 「abraca」 「abra」 「acadabra」 「acada」 「aca」 「adabra」 「ada」 「abra」)
212
+ 'several words here'.match(/\w+/,:global) #(「several」 「words」 「here」)
213
+ 'abcdef'.match(/.*/, :pos(2)) #「cdef」
214
+ "foo[bar][baz]".match(/../, :1st); # 「fo」
215
+ "foo[bar][baz]".match(/../, :2nd); # 「o[」
216
+ "foo[bar][baz]".match(/../, :3rd); # 「ba」
217
+ "foo[bar][baz]".match(/../, :4th); # 「r]」
218
+ "foo[bar][baz]bada".match('ba', :x(2)); # (「ba」 「ba」)
219
+ = end code
220
+
170
221
171
222
= head2 routine parse-base
172
223
0 commit comments