Skip to main content
Skip table of contents

Literal Matching

LAST UPDATED: DECEMBER 29, 2025

A pattern is a Unicode character sequence, including but extending beyond the alphanumeric ASCII set used everyday. In the absence of metacharacters and pattern constructs, literal portions of a pattern are matched exactly and in order against the input text, with matches permitted at any position.

Matching Outcomes

A match succeeds when the pattern matches a contiguous sequence of input characters in order, regardless of position unless constrained by positional constructs.

Examples - Matching Outcomes

Pattern Not Present

EXAMPLE

Input:

CODE
{{ "D3 Security" | regex_match("Management Systems") }}

Return Data:

CODE
False

The pattern "Management Systems" does not appear anywhere in the input text.

Pattern Matches Entire Text

EXAMPLE

Input:

CODE
{{ "D3 Security" | regex_match("D3 Security") }}

Return Data:

CODE
True

The pattern "D3 Security" matches the input text exactly from the first character to the last.

Pattern as a Substring

EXAMPLE

Input:

CODE
{{ "D3 Security" | regex_match("D3") }}

Return Data:

CODE
True

The pattern "D3" appears as a sub-string at the beginning of the input text.

EXAMPLE
Input:

CODE
{{ "D3 Security" | regex_match("Security") }}

Return Data:

CODE
True

The pattern "Security" appears as a sub-string at the end of the input text. Positional constraints are added only when the pattern includes constructs that restrict where a match may occur. See anchors and lookarounds.

EXAMPLE
Input:

CODE
{{ "D3 Security" | regex_match("3 S") }}

Return Data:

CODE
True

The pattern "3 S" appears as a sub-string between other characters in the input text.

Wildcard Character

The . matches any single character, including characters with special meaning, except for \n.

Examples - Wildcard Character

EXAMPLE 1

Input:

CODE
{{ 'xyz' | regex_match('x.z') }}
{{ 'x0z' | regex_match('x.z') }}
{{ 'x_z' | regex_match('x.z') }}
{{ 'x.z' | regex_match('x.z') }}
{{ 'x..z' | regex_match('x.z') }}

Return Data:

CODE
True
True
True
True
False

EXAMPLE 2

Input:

CODE
{{ 'x\ty' | regex_match('x.y') }}
{{ 'x\ny' | regex_match('x.y') }}

Return Data:

CODE
True
False

EXAMPLE 3

Input:

CODE
{{ 'id=7' | regex_match('id=.') }}
{{ 'id=7' | regex_match('id=..') }}
{{ 'id=42' | regex_match('id=.') }}

Return Data:

CODE
True
False
True

Escaping

The \ character removes the special meaning of the subsequent character so it is treated as a literal character.

Supported Escape Sequences

Metacharacters *

TEXT
^ $ \ . * + ? ( ) [ ] { } | /

Backslash Escapes *

Numeric Escapes

  • Hexadecimal bytes
    EXAMPLES

    CODE
    \\x44 \\x33 \x20 \\x53 \\x65 \\x63 \\x75 \\x72 \\x69 \\x74 \\x79
  • Unicode code points
    EXAMPLES

    CODE
    \\u0044 \\u0033 \\u0020 \\u0053 \\u0065 \\u0063 \\u0075 \\u0072 \\u0069 \\u0074 \\u0079

Control Characters

  • \f Form feed

  • \n Newline

  • \r Carriage return

  • \t Horizontal tab

  • \v Vertical tab

Regex Constructs

Examples - Escaping

EXAMPLE 1

Input:

CODE
{{ 'D3 Security' | regex_match('D3\.Security') }}
{{ 'D3 Security' | regex_match('D3.Security') }}

Return Data:

CODE
False
True

EXAMPLE 2

Input:

CODE
{{ 'xy]z' | regex_match('x[y\]][]y]z') }}
{{ 'xy]z' | regex_match('x[y]][y]]z') }}

Return Data:

CODE
True
False

Explanation: A closing square bracket (]) can be matched literally inside a character class either by escaping it (\]) or by placing it first in the character class ([]...]).

EXAMPLE 3

Input:

CODE
{{ 'price: $100' | regex_match('price: \$100') }}
{{ 'price: $100' | regex_match('price: $100') }}

Return Data:

CODE
True
False

Explanation: The \$ matches a literal dollar sign. The unescaped $ in the second line asserts that the pattern (price: ) must end at the end of the string, which fails because in the input string additional characters ($100) follow.

EXAMPLE 4

Input:

CODE
{{ 'price + tax' | regex_match('price \+ tax') }}
{{ 'price + tax' | regex_match('price + tax') }}

Return Data:

CODE
True
False

Explanation: The \+ matches a literal plus sign. The unescaped + in the second line is interpreted as a quantifier that repeats the preceding space one or more times, so the pattern expects price followed by spaces and then tax, which fails because in the input string a literal plus sign appears between the spaces.

EXAMPLE 5

Input:

CODE
{{ 'file(name)' | regex_match('file\(name\)') }}
{{ 'file(name)' | regex_match('file(name)') }}

Return Data:

CODE
True
False

EXAMPLE 6

Input:

CODE
{{ 'abab' | regex_match('(ab)\\1') }}
{{ 'abab' | regex_match('(ab)\1') }}

Return Data:

CODE
True
False

Explanation: For the second expression, Jinja escapes the digit 1 (interpreting \1 as the ASCII SOH control character) during string parsing, so the regex engine received no backreference.

EXAMPLE 7

Input:

CODE
{{ 'D3 Security' | regex_match('\\x44\\x33') }}

Return Data:

CODE
True

Explanation: The hexadecimal values 44 and 33 are converted to their decimal character codes (68 and 51), which correspond to the Unicode characters D and 3 in the ASCII range.

EXAMPLE 8

Input:

CODE
{{ 'D3 Security' | regex_match('\u0044\u0033') }}

Return Data:

CODE
True

Explanation: \u0044 and \u0033 match ASCII characters D and 3, respectively.

SPECIAL REGEX CONSTRUCTS

In some cases, the \ and the following character together form a special regex construct rather than a literal character.

EXAMPLES

FAQs

What are metacharacters and pattern constructs?

Metacharacters are characters with special meaning in a regular expression pattern that modify how matching is performed. Pattern constructs are combinations of metacharacters that define structured matching behavior.

Common examples include the following:

  • . matches any single character except line terminators.

  • [ ] define character classes.

  • ^ and $ constrain match positions.

  • *, +, and ? control repetition.

  • ( ) group sub-patterns.

  • | specifies alternation.

Do spaces count as characters in literal matching?

Yes. Spaces are treated as literal characters.

  • Single space must match exactly.
    EXAMPLE

    CODE
    {{ 'D3 Security' | regex_match('3 S') }}
  • Multiple spaces must match exactly.
    EXAMPLE

    CODE
    {{ 'D3  Security' | regex_match('3  S') }}
  • Missing space causes the match to fail.
    EXAMPLE

    CODE
    {{ 'D3 Security' | regex_match('D3Security') }}
  • Extra space in the pattern causes the match to fail.
    EXAMPLE

    CODE
    {{ 'D3 Security' | regex_match('D3  Security') }}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.