Skip to main content

Replace text based on regex pattern

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)

TitleDescriptionData TypeRequired?
ContentContent containing the value to replaceText(Long)Yes
Regular expressionText(Long)Yes
Replace valueThe 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 replacementsNumberNo

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)

TitleDescriptionData TypeRequired
Edited textText with the value replacedText(Long)Yes

Outcomes

NameDescription
SuccessThis status is selected if the pattern was successfully replaced in the text
Impossible to CompleteThis value is selected if we were unable to evaluate the regular expression.

Examples

ContentRegular expressionReplace ValueMaximum number of replacementsEdited Text
Hello worldworldPython1Hello Python
123-45-6789\d*--***
foo, bar, baz\b\w{3}\babc2abc, abc, baz
One: 1, Two: 2, Three: 3\b\d\b(digit)One: (digit), Two: (digit), Three: (digit)
Main Street 12345\d+#####1Main Street #####
Email: example@test.com(\w+)@(\w+)\.(\w+)\1[at]\2[dot]\31Email: example[at]test[dot]com
The cat sat on the mat.\b\w{3}\b<\0>The on the .
2023-03-15(\d{4})-(\d{2})-(\d{2})\3/\2/\1115/03/2023
Firstname Lastname(\w+) (\w+)\2, \11Lastname, Firstname
"Quote" in a "string""(.*?)"[\1][Quote] in a [string]
Apples, Bananas, Cherries, Dates\b\w+\bFruit2Fruit, Fruit, Cherries, Dates

Version# 1.0