Logmanager documentation
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Unsupported regex constructs

Logmanager guarantees only the regex syntax listed in Regex quick overview. For a regex that uses only this syntax, the time needed to match a message grows only linearly with the length of the message. Such a regex can be turned into a finite automaton (see Thompson’s construction), which reads each character of the message once and never backtracks.

Some constructs that you might know from Perl or Python regular expressions, such as lookahead or backreferences, require backtracking. Backtracking can be slow on crafted input (see ReDoS), so Logmanager doesn’t support these constructs. This page lists the common ones and shows how to rewrite them.

How Logmanager evaluates a regex

When you test or run a parser, Logmanager joins all blocks connected to the by regex input into one regular expression and checks it:

  • Logmanager can match the regex in linear time: Logmanager uses it without any warning.
  • The regex uses a construct that requires backtracking: Logmanager shows a warning and evaluates the regex with a legacy fallback.
  • The regex is invalid, for example because it uses syntax that isn’t listed in Regex quick overview, such as \pL: Logmanager shows a warning that the regex is invalid, and the block returns no values.
Use only the syntax listed in Regex quick overview. Syntax that isn’t listed there may be rejected, accepted, or interpreted differently in any version, even if it works without a warning today.

The warning

When a regex uses an unsupported construct, the Test result shows a warning under Warnings. The warning asks you to optimize the regex, refers to this documentation, and ends with the regex that caused it. The regex in the warning is the complete regex assembled from all blocks connected to by regex. If the regex contains parts that you didn’t write, they come from a substitution used in a Regex assign block. For example, the substitution .*?(?=,|$) assigned to the variable user appears as (?P<user>.*?(?=,|$)). To find the construct, compare the regex with the table of unsupported constructs.

You see the warning in the test result of the Parsers, Classification, and Alert rules editors. The test runs each time you change the Test message or the blocks.

Legacy fallback

Today, a regex with an unsupported construct still works, because Logmanager evaluates it with a legacy fallback mechanism. The fallback isn’t guaranteed to remain: an unsupported construct may stop working in any version. Rewrite affected regexes.

If you see the warning while testing a built-in parser, you don’t need to change anything. If you created your own parser as a copy of a built-in parser, rewrite the regexes in your copy.

Unsupported constructs

The following constructs are marked as not supported in or missing from Regex quick overview. Today, each of them shows the warning.

Construct Example Rewrite
Positive lookahead (?=...) (\w+)=(.*?)(?=;|$) (\w+)=([^;]*), see Lookahead used to end a value
Negative lookahead (?!...) user=(?!SYSTEM\b)(?P<user>\S+) user=(?P<user>\S+) and a condition, see Negative lookahead
Positive lookbehind (?<=...) (?<=src=)(?P<src>\S+) src=(?P<src>\S+), see Lookbehind
Negative lookbehind (?<!...) msg=(?P<msg>.*?)(?<!\\)\| msg=(?P<msg>(?:[^|\\]|\\.)*)\|, see Lookbehind
Backreference \1 msg=(['"])(?P<msg>.*?)\1 msg=["'](?P<msg>[^"']*)["'], see Backreferences
Named backreference (?P=name) src=(?P<src>\S+) dst=(?P=src) src=(?P<src>\S+) dst=(?P<dst>\S+) and a comparison, see Backreferences
Possessive quantifiers *+, ++, ?+, {n,m}+ id=(?P<id>\d++) id=(?P<id>\d+), see Possessive quantifiers and atomic groups
Atomic group (?>...) (?P<proto>(?>tcp|udp)) (?P<proto>(?:tcp|udp))
Conditional (?(1)...) (<)?(?P<host>[\w.]+)(?(1)>) <?(?P<host>[\w.]+)>? (also accepts unpaired brackets)
Inline comment (?#...) (?P<ip>\d+\.\d+\.\d+\.\d+)(?# IPv4) Remove the comment. Use the Comment block instead.
Flags (?x), (?a), (?u) (?x) user= (?P<user>\S+) Remove the flag. For (?x), also remove the spaces: user=(?P<user>\S+). The flags (?i), (?m), and (?s) are supported at the start of the regex, and as (?i:...), (?m:...), and (?s:...) anywhere.
End of text \Z (?P<tail>\w+)\Z (?P<tail>\w+)$
Unicode escapes \uXXXX, \UXXXXXXXX, \N{...} caf\u00e9 The character itself, café, or \xHH for characters up to \xff, caf\xe9
Backspace [\b] a[\b]b a\x08b
Repetition count above 1000 a{1001} a{1000}a

Rewrite recipes

After the rewrite, \w, \d, \s, and \b match only ASCII characters, while the original regex may have matched letters with diacritics. For example, for the message jméno=Jiří;město=Brno, the regex (\w+)=(.*?)(?=;|$) returns jméno: Jiří and město: Brno, while its rewrite (\w+)=([^;]*) returns no: Jiří and sto: Brno. If keys or values can contain such letters, use a negated class such as [^=;\s]+ instead of \w+, and include such messages in your test.

Lookahead used to end a value

The most common use of lookahead in parsers is to find where a value ends without consuming the separator that follows it: (.*?)(?=<separator>) means “take as few characters as possible until the separator follows”.

Don’t just replace the lookahead with (.*?)(?:<separator>|$). That regex stops at the first separator, so a value that contains the separator is silently cut short. Instead, describe the value by what it can’t contain, and then match the separator explicitly:

  • The value can’t contain the separator: use a negated character class.

    Regex Result for user=alice;action=login;result=ok (find all)
    Before (\w+)=(.*?)(?=;|$) user: alice, action: login, result: ok
    After (\w+)=([^;]*) user: alice, action: login, result: ok
  • The value can contain the separator, but not the character that follows each key: exclude that character from the value and match the separator after it. The class [^:]* matches the longest text without : that is followed by the separator or by the end of the message, so the value ends at the last separator before the next key.

    Before: (\w+):\s*(.*?)(?=,\s+\w+:|$)
    After:  (\w+):\s*([^:]*)(?:,\s+|$)
    

    For the message MessageType: Session opened, MessageSubType: , UserName: admin@lab.local, Details: disk full, retrying, Status: failed, both regexes return the same values in the find all mode, including the empty MessageSubType and disk full, retrying for Details. The regex (\w+):\s*(.*?)(?:,\s+|$) returns only disk full for Details.

    The same technique works for other formats, for example for messages with -key=value pairs. This is a lookahead regex for such a format and its rewrite:

    Before: \-([a-zA-Z_0-9]+)\=(.*?(?=\-[a-zA-Z_0-9]+\=|$))
    After:  ([a-zA-Z_0-9]+)=([^=]*)(?:-|$)
    

    Both regexes return the same values for -DevIP=10.0.0.1-Date=2026-11-18-UserName=admin-Result=ok.

This technique works only if the values never contain the excluded character and the keys never contain the separator. For the message Time: 12:30:05, UserName: admin, the regex (\w+):\s*([^:]*)(?:,\s+|$) returns the wrong key 30 with the value 05. For the message Result: ok Update ID: 42, where the separator is a space and the key Update ID contains it, the regex (\w+):\s*([^:]*)(?:\s+|$) returns Result: ok Update and ID: 42. In such cases, extract each field with its own regex in the search mode, for example Time: (?P<time>\d+:\d+:\d+) and UserName: (?P<username>[^,]*).

Negative lookahead

A negative lookahead usually excludes some values, for example all users except SYSTEM. Match the value without the lookahead, and then decide what to do with it in a Controls If statement block with a Logic comparison:

Before: user=(?!SYSTEM\b)(?P<user>\S+)
After:  user=(?P<user>\S+)

For the message logon user=SYSTEM, the original regex doesn’t match, while the rewritten regex returns SYSTEM. Compare user with SYSTEM in the condition and handle the value there.

Lookbehind

  • Positive lookbehind: move the text from the lookbehind in front of the capturing group. The regex parser returns only the groups, so the text before the group doesn’t appear in the result.

    Before: (?<=src=)(?P<src>\S+)
    After:  src=(?P<src>\S+)
    

    Both regexes return src: 10.0.0.1 for proto=tcp src=10.0.0.1 dst=10.0.0.2.

  • Negative lookbehind for escaped separators: describe the value as a sequence of characters that are neither the separator nor a backslash, or a backslash followed by any character.

    Before: msg=(?P<msg>.*?)(?<!\\)\|
    After:  msg=(?P<msg>(?:[^|\\]|\\.)*)\|
    

    Both regexes return msg: disk a\|b full for msg=disk a\|b full|sev=3.

Backreferences

  • Values in single or double quotes: if the value can’t contain a quote, allow both quote characters around it:

    Before: msg=(['"])(?P<msg>.*?)\1
    After:  msg=["'](?P<msg>[^"']*)["']
    

    If the value can contain the other kind of quote, as in msg='it is "fine"', capture the value together with its quotes, msg=(?P<msg>"[^"]*"|'[^']*'), and remove the first and the last character with the Text get substring block.

  • The same value twice: capture both values and compare them with a Logic comparison block.

    Before: src=(?P<src>\S+) dst=(?P=src)
    After:  src=(?P<src>\S+) dst=(?P<dst>\S+)
    
Don’t put different named groups into alternatives, for example "(?P<dq>[^"]*)"|'(?P<sq>[^']*)'. The group that doesn’t take part in the match is stored as the text None.

Possessive quantifiers and atomic groups

Possessive quantifiers and atomic groups prevent backtracking to make a regex faster. A regex with supported syntax never backtracks, so you can remove them: write \d+ instead of \d++ and (?:tcp|udp) instead of (?>tcp|udp).

In rare cases, they also change what the regex matches. For example, a*+a never matches, while a*a does. Test the rewritten regex with your sample logs.

Pitfalls without a warning

The character classes \w, \d, \s, and the word boundary \b match only ASCII characters:

Regex Matches Recommendation
\w Only [0-9A-Za-z_]. user=(?P<user>\w+) returns Ji for user=Jiří logged in. Use \S+ or a negated class, such as [^\s,;]+.
\d Only 0 to 9 Usually what you need in logs.
\b Boundary of ASCII words only. \bkůň\b doesn’t match žluťoučký kůň. Match the surrounding characters, for example (?:^|\s)(?P<w>kůň)(?:\s|$).
\s Only [\t\n\f\r ]: the space, tab, line breaks, and form feed. Not the non-breaking space or other Unicode spaces. Add the characters you need, for example [\s\xa0].

Also avoid the following syntax, which isn’t listed in Regex quick overview:

  • {,n} isn’t guaranteed to mean 0 to n repetitions. Write {0,n}.
  • POSIX classes, such as [[:alpha:]], aren’t guaranteed. Use a range, such as [A-Za-z].

Regexes supplied at runtime

If the by regex input gets the regex from a variable, a lookup table, or another block instead of the Regex match value, Escaped match escaped value, and Regex assign blocks, Logmanager doesn’t know the regex until it processes a message. Currently, it can’t check such a regex, so you don’t see any warning, even if the regex uses an unsupported construct.

To check such a regex, paste it temporarily into a Regex match value block and run the test.

Test a rewritten regex

  1. Open the parser, classifier, or alert rule. To experiment safely, create a copy first.
  2. Insert several sample logs into the Test message field. Include edge cases, such as empty values, values that contain the separator, and the last field of the message.
  3. Note the output of the original regex.
  4. Replace the regex with the rewritten one.
  5. Check that the Warnings in the Test result no longer contain the message about the regex, and that the output is the same as before.