Skip to main content

Regular expressions

Learn how to use regular expressions in Actioner.


Overview

Regular expressions, or regex, are patterns used to find and manipulate text. In Actioner, you can use regex to check data in your inputs and table records.

A regex pattern is a combination of characters and symbols that create a search pattern. This pattern helps you search for specific text in Actioner.

Using regular expressions in Actioner

In Actioner, you can use JavaScript regular expressions to filter and extract information for your inputs and table fields. This makes it easier to control what data is accepted.

Quick reference to regular expressions

Character classes

Character classes are used to match a specific set of characters. They are enclosed in square brackets.

  • g: global match
  • i: case-insensitive match
  • m: multi-line match
PatternEntered valueResult
[abc]hello worldfalse

You can also use ranges to match a range of characters. For example, [a-z] matches all lowercase alphabets, while [0-9] matches all digits.

Metacharacters

Metacharacters are special characters that have a special meaning in regex patterns. Some of the commonly used metacharacters are:

  • . matches any single character except for line terminators
  • * matches zero or more occurrences of the preceding character
  • + matches one or more occurrences of the preceding character
  • ? matches zero or one occurrences of the preceding character
  • ^ matches the start of a string
  • $ matches the end of a string
PatternEntered valueResult
^h.*d$hello worldtrue

You can also use metacharacters to match specific character types. For example, \d matches any digit, while \w matches any word character (alphanumeric characters and underscores).

Grouping

Grouping is used to create a subexpression within a regex pattern. It is enclosed in parentheses.

PatternEntered valueResult
(\w+)\s(\w+)hello worldtrue

You can also use grouping to capture specific parts of the matched string using capturing groups. Captured groups are numbered from left to right, starting from 1.

PatternEntered valueResult
(\d{3})-(\d{3})-(\d{4})My phone number is 123-456-7890123 456 7890

Alternation

Alternation is used to match any one of a set of alternatives. It is represented using the | symbol.

PatternEntered valueResult
`catdog`I love my cat

Lookahead

Lookahead is used to match a pattern only if it is followed by another pattern. It is represented using the (?=) syntax.

PatternEntered valueResult
\d(?= dollars)I have 100 dollarstrue

You can also use negative lookahead to match a pattern only if it is not followed by another pattern. Negative lookahead is represented using the (?! ) syntax.

PatternEntered valueResult
\d(?! dollars)I have 100 poundstrue

Commonly used regular expressions

  1. Match strings only contains numbers
^[0-9]*$
  1. Match the three-letter abbreviations for days of the week
\b(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\b
  1. Match phone numbers in the standard U.S. format: (XXX) XXX-XXXX
^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/\d{4}$
  1. Match Social Security Numbers (SSN) in the format: XXX-XX-XXXX
^\d{3}-\d{2}-\d{4}$
  1. Match URLs starting with http or https
^https?://[^\s/$.?#].[^\s]*$
  1. Match email addresses
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
  1. Match ZIP codes in the standard U.S. format
^\d{5}(-\d{4})?$