Regular Expressions

Graph search, Query Builder, and Workflows can use regular expressions to filter results with matching attributes.

Use regular expressions to create filters with OR conditions, or when complex pattern matching is needed. Otherwise, a built-in operator might already cover your use case (Contains, Starts With, Not Ends With, and others).

Overview

A regular expression is a sequence of characters that define a pattern of symbols to match in search results. At the most basic level, a regular expression works similarly to text search: the regular expression production will match the exact text string "production". More complex expressions can match a pair of values, such as dev|production, or match a sequence of possible characters: [A-Za-z0-9].

Examples

Using a regular expression when filtering results by attribute can enable flexible searches, workflows, and alert rules. Notably, regular expressions allow for matching more than one combination (OR), unlike contains and does not contain filters (where all conditions must be true).

  • Filter by multiple regions: (us-(east|west)-\d+)

  • Match text containing a string: (.*production.*)

  • Filter data resources in all US regions: (us-[A-Za-z]*)

  • Check if a value is an expected format, such as a standard email: \b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b

Notes and Resources

Regular expressions can contain character literals, operators, and constructs. For more information, see:

A variety of sandboxes can be found online for learning, building, and testing regular expressions.

Supported Expressions

Veza implements a subset of Perl Compatible Regular Expressions.

  • Special characters such as *+?()| must be escaped with \

Possible expressions include:

Composites

  • xy - x followed by y

  • x|y - x or y (prefer x)

Repetitions

  • x* - zero or more x, prefer more

  • x+ - one or more x, prefer more

  • x? - zero or one x, prefer one

  • x{n,} - n or more x, prefer more

  • x{n} - exactly n x

  • x*? - zero or more x, prefer fewer

  • x+? - one or more x, prefer fewer

  • x?? - zero or one x, prefer zero

  • x{n,}? - n or more x, prefer fewer

  • x{n}? - exactly n x

Grouping

  • (re) - numbered capturing group (submatch)

  • (?P<name>re) - named & numbered capturing group (submatch)

  • (?:re) - non-capturing group

  • (?flags) - set flags within current group; non-capturing

  • (?flags:re) - set flags during re; non-capturing

Flags

  • i case-insensitive (default false)

  • m multi-line mode (default false)

  • s let . match (default false)

  • U ungreedy: swap meaning of x* and x*?, x+ and x+? (default false)

Flag syntax is xyz (set) or -xyz (clear) or xy-z (set xy, clear z).

Empty Strings

  • ^ - at beginning of text or line

  • $ - at end of text

Character Class Elements

  • . - any character, possibly including newline.

  • x - single character

  • A-Z - character range (inclusive)

  • \d - Perl character class

  • [:class:] - ASCII character class class

  • \p{class} - Unicode character class class

  • \pF - Unicode character class F (one-letter name

  • [\d] - digits (≡ \d)

  • [^\d] - not digits (≡ \D)

  • [\D] - not digits (≡ \D)

  • [^\D] - not not digits (≡ \d)

Perl character classes (ASCII-only)

  • \d - digits (≡ [0-9)

  • \D - not digits (≡ [^0-9)

  • \s - whitespace (≡ [\t\n\f)

  • \S - not whitespace (≡ [^\t\n\f)

  • \w - word characters (≡ [0-9A-Za-z_)

  • \W - not word characters (≡ [^0-9A-Za-z_)

ASCII Character Class

  • [[:alnum:]] - alphanumeric (≡ [0-9A-Za-z])

  • [[:alpha:]] - alphabetic (≡ [A-Za-z])

  • [[:ascii:]] - ASCII (≡ [\x00-\x7F])

  • [[:blank:]] - blank (≡ [\t ])

  • [[:cntrl:]] - control (≡ [\x00-\x1F\x7F])

  • [[:digit:]] - digits (≡ [0-9])

  • [[:graph:]] - graphical (≡ [!-~])

  • [[:lower:]] - lower case (≡ [a-z])

  • [[:print:]] - printable (≡ [ -~][ [:graph:]])

  • [[:punct:]] - punctuation (≡ [!-/:-@[-{-~])

  • [[:space:]] - whitespace (≡ [\t\n\v\f\r ])

  • [[:upper:]] - upper case (≡ [A-Z])

  • [[:word:]] - word characters (≡ [0-9A-Za-z_])

  • [[:xdigit:]] - hex digit (≡ [0-9A-Fa-f])

Last updated