# text.regex_replace · Rell standard library · Chromia Docs (concept)

> function regex_ replace(regex: text , replacement: text ): text Returns the text obtained by replacing all subsequences in this text which match the given 

Source: https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/root/text/regex_replace/

FUNCTION

# text.regex\_replace

```signature
function regex_replace(regex: text, replacement: text): text
```

Returns the text obtained by replacing all subsequences in this text which match the given regular
expression `regex`, with the text `replacement`.

Supports named and numbered group references in the `replacement` text.

Examples:

* `'aaaaacaaaaabaaaaacaaaaa'.regex_replace('(b|c)', 'd')` returns `'aaaaadaaaaadaaaaadaaaaa'`.
* `'aaaaacaaaaabaaaaacaaaaa'.regex_replace('a+', '')` returns `'cbc'`.
* `'johnsmith@chromaway.com'.regex_replace('[a-z]+', '0')` returns `'0@0.0'`.
* `'John Doe'.regex_replace('(\\w+) (\\w+)', '$2, $1')` returns `'Doe, John'`.
* `'2025-10-27'.regex_replace('(?<y>\\d{4})-(?<m>\\d{2})-(?<d>\\d{2})', '${d}/${m}/${y}')`
  returns `'27/10/2025'`.

**Parameters**

* **regex** — the regular expression to search with
* **replacement** — the replacement text

**Returns**

text equal to this, but with regions that match `regex` replaced with `replacement`

**Throws**

* `exception` — if `regex` is not a valid regular expression

Since 0.14.16

[View this page on docs.chromia.com](https://docs.chromia.com/pages/rell-stdlib/-rell%20-system%20-library/%5Broot%5D/text/regex_replace.html)Generated API reference, mirrored from the live docs
