---
name: "regexReplace"
type: command
status: ok
groups: ["Strings - Regular Expression"]
arma3_since: "2.06"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/regexReplace
revid: 349515
updated: 2023-11-08T17:14:41Z
---

# regexReplace

*Command · Strings - Regular Expression · Arma 3 v2.06*

## Description

Searches given *haystack* with given *pattern* and replaces all matches with given *replaceString*.

## Syntax

```sqf
haystack regexReplace [pattern, replaceString]
```

**Parameters:**

- `haystack`: [String](../topics/String.md)
- `pattern`: [String](../topics/String.md) - format regex pattern
- `replaceString`: [String](../topics/String.md) - [Reference](https://www.boost.org/doc/libs/1_76_0/libs/regex/doc/html/boost_regex/format/perl_format.html)

**Returns:** [String](../topics/String.md) - modified text

## Examples

### Example 1

```sqf
"wookie boOkie cookie" regexReplace [".oo/gio", "[$']"];                        // "[kie boOkie cookie]kie [kie cookie]kie [kie]kie"
```

### Example 2

```sqf
"wookie boOkie cookie" regexReplace [".oo/gio", "[$&]"];                        // "[woo]kie [boO]kie [coo]kie"
```

### Example 3

```sqf
"wook1e boOk2e cook3e" regexReplace [".oo/gio", "[$`]"];                        // "[]kie [k1e ]k2e [k2e ]k3e"
```

### Example 4

```sqf
"wook1e boOk2e cook3e" regexReplace [".(oo)(.*?)e", "[$2]"];                    // "[k1] [k2] [k3]"
```

### Example 5

```sqf
"wOokie boOkie cookie" regexReplace [".(?<test>oo)kie/gio", "[$+{test}]"];    // "[oo] [oO] [oo]"
```

### Example 6

```sqf
// Make captured group all lower case '\L' (lower case) or '\U' (upper case)
"ArmA 3 is so awesome!" regexReplace ["(rmA 3)", "\L$1"]; // "Arma 3 is so awesome!"
```

## See also

[regexMatch](../commands/regexMatch.md) · [regexFind](../commands/regexFind.md)

<sub>Source: [BI Community Wiki — regexReplace](https://community.bistudio.com/wiki/regexReplace) (revision 349515).</sub>
