---
schema_version: "1"
id: 13ab959db9c83c472adca5eeeb5ef5cb609a77b2ea8bf5796f877301cbb8157e
title: toRegex
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/latest/dw-coercions-functions-toregex.md
canonical_url: https://docs.mulesoft.com/dataweave/latest/dw-coercions-functions-toregex
source_site: docs.mulesoft.com
content_type: documentation
content_hash: dc31126b75dda044925d9fe8e9584b6c3d62389b7551383ae4c13baaf46afa2f
description: MuleSoft Documentation Site
release: "2.13"
latest: true
---
---
product: DataWeave
version: 2.13
is-latest-version: true
---

# 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+/
}
```
