Vocabulary
regexp

Inputs
stringa string
regexpa regexp
quota quotation with stack effect ( slice -- replacement )


Outputs
resulta 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


:: 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 ;