Contact Us 1-800-596-4880

toRegex

toRegex(str: String): Regex

Transforms a String value into a Regex value.

Introduced in DataWeave version 2.4.0.

Parameters

Name Description

str

The String value to transform into a Regex value.

Example

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

Source

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

Output

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