Replace Patterns

Find and replace any of multiple patterns with a single value. For any find and replace that looks for a single text or pattern, use Replace instead.

Input Fields

  • look in is the full text to start with.

  • replace with is the text to replace any instances found, or leave it empty if you want to remove them (i.e. replace them with nothing).

  • all instances - set to True to replace all matches, or False to replace just the first instance that is found.

  • case sensitive - set to True if the case of any pattern must be an exact match. If False, then Test would match test, TEST, and tEsT.

  • patterns - unlike the Replace function that searches for a single text or pattern, patterns allows you to add multiple texts or patterns to search for - all to be replaced with the same replace with text. Add a new input to the patterns section for each additional pattern you want to search. The name of each input is ignored.

Output Fields

  • result text is the resulting text after any replacements are made. If no instances of the patterns are found, then result text is the same as the input look in.

Example Usage:

You could use this function to strip out a set of characters from a larger look in text. To do this, add fields in the patterns section, one for each string you want to strip out, and leave replacement blank.

You could use this function to obscure certain characters in text by replacing them with an asterisk.

Pattern Options

Each Pattern can be simple text to search for or can be a more complex pattern, using a standard pattern format called regular expressions. Examples of regular expressions include:

  • \w - finds any alphanumeric character (e.g. a letter or number)

  • \s - finds any white-space character (e.g. a blank or tab)

  • \d - finds any digit

  • [1-5] - finds a number between 1 and 5

  • [aeiou] - finds a, e, i, o, or u

  • hello|test - finds "hello" or "test"

  • colou?r - finds "color" or "colour" (the ? signifies that there can be zero or one of the preceding element)

  • \d{5} - finds five consecutive digits (the {number} signifies a number of consecutive instances of the preceding element)

  • [^\w] - finds any character that is not an alphanumeric character. You can add the not operator ^ before any other pattern, e.g. [^a] to find anything other than a or [^\d{3}] to find anything that is not 3 digits in a row

Many characters have special meaning in regular expressions, such as ., +, *, \ and more. To search for any of those characters you need to place a \ before the character. For instance:

  • \. - finds a period

You can combine any of the above patterns and fixed text. For instance:

  • test\.\d{3} - finds the word "test" followed by a period followed by 3 consecutive digits

See Find Pattern for more pattern examples.

See Also

Functions in Workflows

About the elements of Okta Workflows