🧡 Skip to main content🔍 Skip to search
Thomas UnderwoodBy Thomas Underwood 🕤 Updated on January 3, 2024 at 9:30 am

Regular expression is a pattern of characters that can be used to find various text sequences. The If Action allows comparing data or text string against Perl-compatible regular expressions (PCRE). Regular expressions allow using special symbols as wildcards, anchors, sub-expressions, repeats and other functions to match text in advanced, non-linear ways.

Overview

Automation Workshop allows designing advanced conditional branching by applying regular expressions to dynamic variables, e.g., Action outputs, to find necessary patterns in that data.

Even if the text itself is each time slightly different, extracting of particular values might still be possible. When the specified pattern is found, the If Action will execute one branch of Actions rather than another. See typical usage of some simple regular expressions…

Regex basics

  • [0-9]{3} · matches the number pattern in a range of 000, 001, 002 … 997, 998, 999.
  • (?:\d[ -]*?){13,16} · matches any sequence of 13 to 16 digits with spaces or dashes.
  • <DIV\b[^>]*>(.*?)</DIV> · matches the opening and closing pair of a DIV tag with an optional HTML attributes.

Regex & Actions

  • If Action · used for regex compare functions Matches regular expression, Contains regular expression, Does not match regular expression and Does not contain regular expression.
  • Find Text Action · regular expressions can be used when searching for a text in a text string.
  • Find & Replace Text Action · regex can be used when searching and replacing text in a text string.

Extended search patterns

  • Enclosed Text Action · an easier method to extract simple structured text fields using the starting and ending marks (aka tags).
Use Regular Expression filter to specify a search pattern in text

Regex replace example

Regex Details
Text string Invoice for 129, excluding tax 20. 149 total.
Find what \d+
Replace with USD $0
Result Invoice for USD 129, excluding tax USD 20. USD 149 total.

Regex replace more

Regex Details
Text string "US","John","email@example.com","ID2047"
Find what "(.*)","(.*)","(.*)","ID(.*)"
Replace with Order #$4 by $2 from $1 using $3 address.
Result Order #2047 by John from US using email@example.com address.

Regex & smart capture

Regex Example
Text string <name>John</name><year>1976</year>
Find what <name>(.?)</name><year>(.?)</year>
Result John | 1976

Notes

  • It is possible to use inline comments using (?#this is comment) syntax.
  • Escape characters are supported, for example \x64 stands for a, and \x42 stands for B.
  • Automation Workshop supports regular expression flag modifiers (?imsx-imsx).
    • i · do case-insensitive pattern matching.
    • m · treat string as multiple line.
    • s · treat string as single line.
    • x · extend your pattern's readability by permitting whitespaces.

Regex simplify

Although Automation Workshop does not fully support variable-length lookbehind regular expression assertions, a regex pattern can usually be modified to workaround this limitation.

  • Ensure that the lookbehind assertion has a fixed width. Variable-width lookbehinds (for example, using quantifiers such as * or +) may not be supported. Also, a capturing group that is located within lookbehind may not be fully supported.
  • If the lookbehind is complex, try simplifying it. Break down the regex into simpler components and test them individually to pinpoint the issue.
  • Alternatively, restructure the regex to use lookahead assertions instead of lookbehind. Lookahead assertions are generally more flexible and widely supported.
  • Consider whether the same result can be achieved without using lookbehind. Sometimes, a combination of string manipulation and simpler regex can replace a complex pattern.
  • When modifying the regex, test it incrementally. Make small changes and test after each change to identify what works and what causes the error. Try to avoid using lookbehind if it causes an error.

Learn more?

Try now!

  • Regex101 · online regex editor and debugger.
  • RegExr · learn, build & test regex.

Help at your fingertips…

If you have any questions, please do not hesitate to contact our support team.