---
schema_version: "1"
id: 236c780946377a46ab6d0fbc3365b7c9d000c994a523cb04d6266f173b21d7fe
title: toRegex
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-coercions-functions-toregex.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-toregex
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 0b4a814de300311c902177f0877ec5dbecb6eb490ef4a4855d3e09593ec6b2b4
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# toRegex

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## toRegex(str: String): Regex

Transforms a `String` value into a `Regex` value.

_Introduced in DataWeave version 2.4.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>str</code></p></td><td><p>The <code>String</code> value to transform into a <code>Regex</code> value.</p></td></tr></tbody></table>

### Example

This example shows how `toRegex` behaves with different inputs. It produces output in the
`application/dw` format.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::Coercions
output application/dw
---
{
  toRegexEx1: toRegex("a-Z"),
  toRegexEx2: toRegex("0-9+")
}
```

#### Output

```DataWeave
{
  toRegexEx1: /a-Z/,
  toRegexEx2: /0-9+/
}
```
