tur/re-string
stdlib/re-string.tur
owned String siblings for the tur/re string builders.
Since: v2 (string-adoption-stdlib-plan, batch 3)
defn
re/replace-string
(re/replace-string [re : Regex input : cstr replacement : cstr] :)
replace the first match with a literal, as an owned
Parameters
| re | compiled Regex from re/compile | |
| input | input string cstr | |
| replacement | literal replacement cstr (no backreferences) |
Returns
An owned String with the first match replaced (a copy of the input if there is no match).
Example
(string/to-cstr (re/replace-string (re/compile "[0-9]") "a1b2" "X")) ; => "aXb2"
Since: v2
defn
re/replace-all-string
(re/replace-all-string [re : Regex input : cstr replacement : cstr] :)
replace all non-overlapping matches with a literal,
Parameters
| re | compiled Regex from re/compile | |
| input | input string cstr | |
| replacement | literal replacement cstr (no backreferences) |
Returns
An owned String with every match replaced.
Example
(string/to-cstr (re/replace-all-string (re/compile "[0-9]") "a1b2c3" "X")) ; => "aXbXcX"
Since: v2
defn
re/union-patterns-string
(re/union-patterns-string [patterns : int] :)
build an alternation regex from a cons list of
Parameters
| patterns | :int cons list of cstr patterns (head = cstr pointer) |
Returns
An owned String of the unioned pattern, or an empty String if the list is empty or contains a null element.
Example
(string/to-cstr (re/union-patterns-string (cons "[A-Za-z]+" (cons "[0-9]+" 0)))) ; => "([A-Za-z]+)|([0-9]+)"
Since: v2