Handbook
Glossary
first-match ( string regexp -- slice/f )
Regular expressions
ยป
Matching operations with regular expressions
Prev:
re-contains? ( string regexp -- ? )
Next:
first-match-with-captures ( string regexp -- match/f )
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
_
<slice-unsafe>
]
[
2drop
f
]
if
;