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 )
[
prepare-match-iterator
do-next-match
]
2keep
swap
[
[
reverse-regexp?
[
[
1
+
]
bi@
]
when
]
curry
]
dip
[
<slice-unsafe>
]
curry
compose
[
2drop
f
]
if
;