Qu

regex_replace

Builtin index · Collections & strings

result = regex_replace(s, pattern, repl, [count], [keep=])

Input: s, pattern, repl, count, keep · Output: result

What it is

Replaces every match of the regular expression pattern in s with repl. s, pattern and repl are Strs; optional count (number, default: all occurrences) caps how many replacements are made. $1 and ${name} in repl refer to capture groups. Optional keep= (a regex, or a List of them) leaves alone any match that falls inside text it matches -- the stand-in for lookahead, which Qu's regex engine does not have.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = regex_replace(s, pattern, repl, [count], [keep=])
s Strs, pattern and repl are Strs.
pattern —Replaces every match of the regular expression pattern in s with repl.
repl —Replaces every match of the regular expression pattern in s with repl.
count number, optionaloptional count (number, default: all occurrences) caps how many replacements are made.
keep List, optionalOptional keep= (a regex, or a List of them) leaves alone any match that falls inside text it matches -- the stand-in for lookahead, which Qu's regex engine does not have.
result Str
Returns a Str.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

print(regex_find_all("a1b22c333", "[0-9]+"))                                          # ("1", "22", "333")

print(regex_replace("2026-09-07", "([0-9]+)-([0-9]+)-([0-9]+)", "$3/$2/$1"))          # "07/09/2026"

print(regex_groups("v1.2.3", "v([0-9]+)\.([0-9]+)"))                                  # ("1", "2")

print(like("hello.txt", "*.txt"))                                                      # true

output
("1", "22", "333")
07/09/2026
("1", "2")
true

from collections-strings

How it works

regex_replace(s, pattern, replacement, [count]) — $1 and ${name} in the replacement refer to capture groups. Every occurrence unless count says otherwise.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.