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:

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

Return Data:

False

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

Pattern Matches Entire Text

Example

Input:

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

Return Data:

True

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

Pattern as a Substring

Example

Input:

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

Return Data:

True

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

Example
Input:

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

Return Data:

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:

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

Return Data:

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:

{{ '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:

True
True
True
True
False

Example 2

Input:

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

Return Data:

True
False

Example 3

Input:

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

Return Data:

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 *

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

Backslash Escapes *

Numeric Escapes

  • Hexadecimal bytes
    examples

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

    \\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:

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

Return Data:

False
True

Example 2

Input:

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

Return Data:

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:

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

Return Data:

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:

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

Return Data:

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:

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

Return Data:

True
False

Example 6

Input:

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

Return Data:

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:

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

Return Data:

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:

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

Return Data:

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

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

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

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

    {{ 'D3 Security' | regex_match('D3  Security') }}