Skip to main content
All CollectionsWrk Action LibraryLogic
Replace text based on regex pattern
Replace text based on regex pattern
Wrk Product avatar
Written by Wrk Product
Updated over a week ago

Identify and replace all parts of a text that match a regular expression, which is a sequence of characters that specifies a search pattern.

Regular Expressions

Application

  • Text

Inputs (what you have)

Title

Description

Data Type

Required?

Content

Content containing the value to replace

Text(Long)

Yes

Regular expression

Text(Long)

Yes

Replace value

The value used as a replacement. If left blank this will cause the found text to be removed. To use a back reference enter the following format '\\{Group Number}'

Text(Long)

No

Maximum number of replacements

Number

No

Note: the value of inputs can either be a set value in the configuration of the Wrk Action within the Wrkflow, or a variable from the Data library section. These variables in the Data library section are the outputs of previous Wrk Actions in the Wrkflow.


Outputs (what you get)

Title

Description

Data Type

Required

Edited text

Text with the value replaced

Text(Long)

Yes

Outcomes

Name

Description

Success

This status is selected if the pattern was successfully replaced in the text

Impossible to Complete

This value is selected if we were unable to evaluate the regular expression.

Examples

Content

Regular expression

Replace Value

Maximum number of replacements

Edited Text

Hello world

world

Python

1

Hello Python

123-45-6789

\d

*

--***

foo, bar, baz

\b\w{3}\b

abc

2

abc, abc, baz

One: 1, Two: 2, Three: 3

\b\d\b

(digit)

One: (digit), Two: (digit), Three: (digit)

Main Street 12345

\d+

#####

1

Main Street #####

(\w+)@(\w+)\.(\w+)

\1[at]\2[dot]\3

1

Email: example[at]test[dot]com

The cat sat on the mat.

\b\w{3}\b

<\0>

The <cat> <sat> on the <mat>.

2023-03-15

(\d{4})-(\d{2})-(\d{2})

\3/\2/\1

1

15/03/2023

Firstname Lastname

(\w+) (\w+)

\2, \1

1

Lastname, Firstname

"Quote" in a "string"

"(.*?)"

[\1]

[Quote] in a [string]

Apples, Bananas, Cherries, Dates

\b\w+\b

Fruit

2

Fruit, Fruit, Cherries, Dates


โ€‹

Version# 1.0


โ€‹

Did this answer your question?