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 matchi
: case-insensitive matchm
: multi-line match
Pattern | Entered value | Result |
---|---|---|
[abc] | hello world | false |
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
Pattern | Entered value | Result |
---|---|---|
^h.*d$ | hello world | true |
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.
Pattern | Entered value | Result |
---|---|---|
(\w+)\s(\w+) | hello world | true |
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.
Pattern | Entered value | Result |
---|---|---|
(\d{3})-(\d{3})-(\d{4}) | My phone number is 123-456-7890 | 123 456 7890 |
Alternation
Alternation is used to match any one of a set of alternatives. It is represented using the |
symbol.
Pattern | Entered value | Result |
---|---|---|
`cat | dog` | 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.
Pattern | Entered value | Result |
---|---|---|
\d(?= dollars) | I have 100 dollars | true |
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.
Pattern | Entered value | Result |
---|---|---|
\d(?! dollars) | I have 100 pounds | true |
Commonly used regular expressions
- Match strings only contains numbers
^[0-9]*$
- Match the three-letter abbreviations for days of the week
\b(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\b
- 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}$
- Match Social Security Numbers (SSN) in the format: XXX-XX-XXXX
^\d{3}-\d{2}-\d{4}$
- Match URLs starting with http or https
^https?://[^\s/$.?#].[^\s]*$
- Match email addresses
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
- Match ZIP codes in the standard U.S. format
^\d{5}(-\d{4})?$