Handbook
Glossary
first-match ( string regexp -- slice/f )
Regular expressions
ยป
Matching operations with regular expressions
Prev:
re-contains? ( string regexp -- ? )
Next:
count-matches ( string regexp -- n )
Vocabulary
regexp
Inputs
string
a
string
regexp
a
regexp
Outputs
slice/f
the match, if one exists
Word description
Finds the first match of the regular expression in the string, and returns it as a slice. If there is no match, then
f
is returned.
Definition
USING:
kernel
math
regexp.private
sequences.private
;
IN:
regexp
::
first-match
( string regexp -- slice/f )
string regexp
prepare-match-iterator
do-next-match
[
regexp
reverse-regexp?
[
[
1
+
]
bi@
]
when
string
<slice-unsafe>
]
[
2drop
f
]
if
;