Regular Expression

This action is not fully bounded by your Office 365 tenancy. It either calls outside of the tenant or executes on servers potentially running outside your region. Before implementing, consider performance and regional concerns where digital boundaries are an issue.

Performs an operation on the specified string using a regular expression (pattern). Operations include replacing, splitting, and extracting strings, as well as checking for a match.

Note: For more information about regular expressions, see the following Microsoft article: .NET Framework Regular Expressions.

What can I do with this workflow action?

You can use this action to split a string based on its delimiter, such as a comma or semicolon. If you place this action within a loop action, such as For Each, then you can process each individual value split from the string. You may want to include the action to prevent processing of empty values.

In addition to splitting strings, you can use this action to check for a match in a string, search and replace substrings within a string, and extract substrings. This action is useful for working with long bits of data from lists, web services, databases, and other sources that provide data in delimited form.

Action settings

Following are the fields and options visible in the configuration settings dialog box for this action. For more information about the configuration settings dialog box, see Configuration settings dialog box.

Field Description
String

The input string to which the regular expression will be applied.

Advanced Lookup: Displays available lookups. Click Insert to insert the specified configuration into the field. For more information, see Work with lookups.

String operation

Operation to perform on the input string.

  • Replace: Replaces the part of the string matching the pattern with the replacement string. Outputs the resulting string.
  • Check Match: Determines if the input string matches the pattern. Outputs a yes/no value.
  • Split: Divides the input string into sections using the pattern as a delimiter. Outputs a collection variable containing each portion of the split text.
  • Extract: Searches the input string for substrings that match the pattern. Outputs a collection variable containing each matching substring.
Pattern

The regular expression pattern to apply to the input string.

Note: Use Microsoft .NET regular expression syntax, as described in the following Microsoft article: Regular Expression Language - Quick Reference.

Example expression pattern Match Common usage
; Semicolon (";") Split string wherever a semicolon appears.
;|, Semicolon or comma (";" or ",") Split string wherever a semicolon or comma appears.
\. Period (".")

Split string wherever a period appears.

Note: Because a period is a special character, it is escaped.

\s Any white space character Split string wherever a space appears or replace spaces with no text to remove spaces.
[a-zA-Z\d][a-zA-Z\d ]+$ Space, hyphen, space (" - ") Split string based on the following delimiter: " - " (space, hyphen, space).
(?<=\w+\s-\s)\w+ Either space, hyphen, space, or space, hyphen, hyphen, space

Split string based on the following delimiters: 

" - " (space, hyphen, space)

" -- " (space, hyphen, hyphen, space)

[0-9]+ One or more consecutive numbers Replace, check match, or extract any set of one or more consecutive numbers in the string.
[\d]+ One or more consecutive numbers Replace, check match, or extract any set of one or more consecutive numbers in the string.

Ignore case: When selected, treats pattern as case-insensitive. For example, when selected, a pattern value of "T" matches both "T" and "t".

Advanced Lookup: Displays available lookups. Click Insert to insert the specified configuration into the field. For more information, see Work with lookups.

Replacement string

String with which to replace any string that matches the pattern.

Advanced Lookup: Displays available lookups. Click Insert to insert the specified configuration into the field. For more information, see Work with lookups.

Output

The workflow variable in which to store the output from the operation.

The type of variable needed depends on the selection for String operation.

  • Replace: Text variable.
  • Check Match: Boolean variable.
  • Split: Collection variable.
  • Extract: Collection variable.

Tip: When testing or troubleshooting collection variable outputs, you may find it useful to count individual items in the output collection variable using Count Items in Collection then log the count using Log to History List.

Related information

Working with collection variables