Handbook
Glossary
re-replace-with ( string regexp quot: ( slice -- replacement ) -- result )
Regular expressions
ยป
Matching operations with regular expressions
Prev:
re-replace ( string regexp replacement -- result )
Vocabulary
regexp
Inputs
string
a
string
regexp
a
regexp
quot
a
quotation
with stack effect
( slice -- replacement )
Outputs
result
a
string
Word description
Replaces substrings which match the input regexp with the result of calling
quot
on each matching slice. The boundaries of the substring are chosen by the strategy used by
all-matching-slices
.
Examples
USING: ascii prettyprint regexp ; "abcdefghi" R/ [aeiou]/ [ >upper ] re-replace-with .
"AbcdEfghI"
See also
re-replace
Definition
USING:
combinators
kernel
make
sequences
sequences.private
;
IN:
regexp
::
re-replace-with
( string regexp quot: ( slice -- replacement ) -- result )
[
0 string regexp
[
drop
[
[
string
<slice-unsafe>
,
]
keep
]
dip
[
string
<slice-unsafe>
quot ( x -- x )
call-effect
,
]
keep
]
each-match
string
[
length
]
[
<slice-unsafe>
]
bi
,
]
{
}
make
concat
;