---
title: "replaceregex Formula Function: Replace Text with Regular Expressions in Nodinite Search Fields"
description: "The replaceregex Formula function replaces every regular expression match in the message body, a context property, or another function's result. Use capturing groups such as $1 to reshape values."
---

# <i class="fal fa-function" aria-hidden="true"></i> Formula - replaceregex

The `replaceregex` [Formula][] function returns the content with every match of a regular expression replaced by `newValue`.

![Extract the ERP reference with regex and strip its prefix with replaceregex, animated walkthrough (7.12)][2]  
*Animated walkthrough: on the Order Entry XML of the [Order-to-Cash demo][], `regex` first finds the ERP reference `ERP-2025-10005`; wrapped in `replaceregex`, the `ERP-2025-` prefix is replaced by an empty string and `10005` remains.*  

## <i class="fal fa-code" aria-hidden="true"></i> Syntax

```text
replaceregex('pattern', 'newValue', content)
```

### Parameters

|Parameter|Required|Description|
|---|---|---|
|`'pattern'`|Yes|A .NET regular expression. Write backslashes once, for example `'\d+'`; see the [Formula language rules][].|
|`'newValue'`|Yes|The text to substitute for each match. `$1`, `$2`, and so on insert the capturing groups of the match (Example 4).|
|`content`|Yes|The text to change: [body][], [context][], or the result of another function, such as [xPath2][].|

### Returns

The content with all matches replaced. [Content][] without a match is returned unchanged. When the content holds several values, the replacement runs on each value: `replaceregex('a', 'b', …)` on the two values `aa` and `ca` returns `bb` and `cb`.

## <i class="fal fa-list-ol" aria-hidden="true"></i> Examples

### Example 1: Mask every digit

#### Input

```xml
<ProjectNumber>1401518</ProjectNumber>
```

#### Formula

```text
replaceregex('[0-9]', 'X', body)
```

#### Result

```text
<ProjectNumber>XXXXXXX</ProjectNumber>
```

![Test Expression tab: replaceregex with the digit class 0-9 and X on the body turns ProjectNumber 1401518 into XXXXXXX (7.12)][ex1]  
*Each digit is a separate match, so all seven digits are replaced one by one.*  

### Example 2: Replace a fixed word

#### Input

```xml
<Action>DELETE</Action>
```

#### Formula

```text
replaceregex('DELETE', 'UPDATE', body)
```

#### Result

```text
<Action>UPDATE</Action>
```

![Test Expression tab: replaceregex('DELETE', 'UPDATE', body) changes the Action element from DELETE to UPDATE (7.12)][ex2]  
*A pattern without special characters matches the word as is; [replace][] gives the same result without regular expression syntax.*  

### Example 3: Mask an element value

#### Input

```xml
<Company>400</Company>
```

#### Formula

```text
replaceregex('<Company>[0-9]+</Company>', '<Company>XXX</Company>', body)
```

#### Result

```text
<Company>XXX</Company>
```

![Test Expression tab: replaceregex masks the Company value 400 as XXX and keeps the element tags (7.12)][ex3]  
*The pattern matches the whole element, so `newValue` writes the tags back around the mask.*  

### Example 4: Build one value per record with capturing groups

[xPath2][] returns each inner `TypedPollingResultSet0` record. The pattern captures `Company`, `Activity`, and `Action`, and `'$1|$2|$3'` replaces the whole record with the three captured values.

#### Input

```xml
<TypedPolling>
    <TypedPollingResultSet0>
        <TypedPollingResultSet0>
            <ProjectNumber>1401518</ProjectNumber>
            <Company>400</Company>
            <Activity>1000</Activity>
            <Version>20250301060028</Version>
            <Action>DELETE</Action>
        </TypedPollingResultSet0>
        <TypedPollingResultSet0>
            <ProjectNumber>1401518</ProjectNumber>
            <Company>400</Company>
            <Activity>1001</Activity>
            <Version>20250301060028</Version>
            <Action>DELETE</Action>
        </TypedPollingResultSet0>
        <TypedPollingResultSet0>
            <ProjectNumber>4831351</ProjectNumber>
            <Company>355</Company>
            <Activity>1063</Activity>
            <Version>20250301060028</Version>
            <Action>DELETE</Action>
        </TypedPollingResultSet0>
        <TypedPollingResultSet0>
            <ProjectNumber>9233120</ProjectNumber>
            <Company>700</Company>
            <Activity>3400</Activity>
            <Version>20250301060028</Version>
            <Action>DELETE</Action>
        </TypedPollingResultSet0>
        <TypedPollingResultSet0>
            <ProjectNumber>9402000</ProjectNumber>
            <Company>734</Company>
            <Activity>5104</Activity>
            <Version>20250301060028</Version>
            <Action>DELETE</Action>
        </TypedPollingResultSet0>
    </TypedPollingResultSet0>
</TypedPolling>
```

#### Formula

```text
replaceregex('.+<Company>(.+)</Company>.+<Activity>(.+)</Activity>.+<Action>(.+)</Action>','$1|$2|$3',xPath2('/TypedPolling/TypedPollingResultSet0/TypedPollingResultSet0',body))
```

#### Result

```text
400|1000|DELETE
400|1001|DELETE
355|1063|DELETE
700|3400|DELETE
734|5104|DELETE
```

![Test Expression tab: replaceregex with capturing groups on xPath2 records returns five values such as 400|1000|DELETE (7.12)][1]  
*Five records give five unique values, each built from the `Company`, `Activity`, and `Action` of one record.*  

## <i class="fal fa-circle-info" aria-hidden="true"></i> Notes

* To replace plain text without regular expression syntax, use [replace][]; it treats every character literally.
* To extract matches instead of replacing them, use [regex][] or [regexGroup][].

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Add or manage Search Field][]  
* <i class="fal fa-flask" aria-hidden="true"></i> [Test Your Expression][]  
* <i class="fal fa-hard-drive" aria-hidden="true"></i> [Add or manage Log View][]  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-link" aria-hidden="true"></i> [concat][]  
* <i class="fal fa-eraser" aria-hidden="true"></i> [removebom][]  
* <i class="fal fa-right-left" aria-hidden="true"></i> [replace][]  
* <i class="fal fa-scissors" aria-hidden="true"></i> [substring][]  
* <i class="fal fa-function" aria-hidden="true"></i> [Formula][]  
* <i class="fal fa-scroll" aria-hidden="true"></i> [Formula language rules][]  
* <i class="fal fa-puzzle-piece" aria-hidden="true"></i> [Search Field Expressions][]  

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Alter/regexreplace.png
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Formula_RegexReplace.gif

[Add or manage Log View]:https://docs.nodinite.com/administration/log-management/log-views/features/add-or-manage-log-view/
[Add or manage Search Field]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/
[body]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/body/
[concat]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/alter/concat/
[Content]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/#fa-scroll-formula-language-rules
[Context]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/context/
[ex1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Alter/ReplaceRegEx_Example1.png
[ex2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Alter/ReplaceRegEx_Example2.png
[ex3]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Alter/ReplaceRegEx_Example3.png
[Formula]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/
[Formula language rules]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/#fa-scroll-formula-language-rules
[Order-to-Cash demo]:https://docs.nodinite.com/repository-model/bpms/examples/order-to-cash/generate-o2c-demo-data/
[regex]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/regex/
[regexGroup]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/regexgroup/
[removebom]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/alter/removebom/
[replace]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/alter/replace/
[Search Field Expressions]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/
[substring]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/alter/substring/
[Test Your Expression]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/#test-your-expression
[xPath2]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath2/