Back to Beats

Regular expression support [regexp-support]

docs/reference/auditbeat/regexp-support.md

9.4.04.9 KB
Original Source

Regular expression support [regexp-support]

Auditbeat regular expression support is based on RE2.

Before using a regular expression in the config file, refer to the documentation to verify that the option you are setting accepts a regular expression.

::::{note} We recommend that you wrap regular expressions in single quotation marks to work around YAML’s string escaping rules. For example, '^\[?[0-9][0-9]:?[0-9][0-9]|^[[:graph:]]+'. ::::

For more examples of supported regexp patterns, see Managing Multiline Messages. Although the examples pertain to Filebeat, the regexp patterns are applicable to other use cases.

The following patterns are supported:

PatternDescription
$$$single-characters$$$Single Characters
xsingle character
.any character
[xyz]character class
[^xyz]negated character class
[[:alpha:]]ASCII character class
[[:^alpha:]]negated ASCII character class
\dPerl character class
\Dnegated Perl character class
\pNUnicode character class (one-letter name)
\p{{Greek}}Unicode character class
\PNnegated Unicode character class (one-letter name)
\P{{Greek}}negated Unicode character class
$$$composites$$$Composites
xyx followed by y
x|yx or y (prefer x)
$$$repetitions$$$Repetitions
x*zero or more x
x+one or more x
x?zero or one x
x{n,m}n or n+1 or … or m x, prefer more
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,m}?n or n+1 or … or m x, prefer fewer
x{n,}?n or more x, prefer fewer
x{{n}}?exactly n x
$$$grouping$$$Grouping
(re)numbered capturing group (submatch)
(?P<name>re)named & numbered capturing group (submatch)
(?:re)non-capturing group
(?i)abcset flags within current group, non-capturing
(?i:re)set flags during re, non-capturing
(?i)PaTTeRNcase-insensitive (default false)
(?m)multilinemulti-line mode: ^ and $ match begin/end line in addition to begin/end text (default false)
(?s)pattern.let . match \n (default false)
(?U)x*abcungreedy: swap meaning of x* and x*?, x+ and x+?, etc (default false)
$$$empty-strings$$$Empty Strings
^at beginning of text or line (m=true)
$at end of text (like \z not \Z) or line (m=true)
\Aat beginning of text
\bat ASCII word boundary (\w on one side and \W, \A, or \z on the other)
\Bnot at ASCII word boundary
\zat end of text
$$$escape-sequences$$$Escape Sequences
\abell (same as \007)
\fform feed (same as \014)
\thorizontal tab (same as \011)
\nnewline (same as \012)
\rcarriage return (same as \015)
\vvertical tab character (same as \013)
\*literal *, for any punctuation character *
\123octal character code (up to three digits)
\x7Ftwo-digit hex character code
\x{{10FFFF}}hex character code
\Q...\Eliteral text ... even if ... has punctuation
$$$ascii-character-classes$$$ASCII Character Classes
[[:alnum:]]alphanumeric (same as [0-9A-Za-z])
[[:alpha:]]alphabetic (same as [A-Za-z])
[[:ascii:]]ASCII (same as \x00-\x7F])
[[:blank:]]blank (same as [\t ])
[[:cntrl:]]control (same as [\x00-\x1F\x7F])
[[:digit:]]digits (same as [0-9])
[[:graph:]]graphical (same as [!-~] == [A-Za-z0-9!"#$%&'()*+,\-./:;<=>?@[\\\]^_` {&#124;}~])
[[:lower:]]lower case (same as [a-z])
[[:print:]]printable (same as [ -~] == [ [:graph:]])
[[:punct:]]punctuation (same as [!-/:-@[-`{-~])
[[:space:]]whitespace (same as [\t\n\v\f\r ])
[[:upper:]]upper case (same as [A-Z])
[[:word:]]word characters (same as [0-9A-Za-z_])
[[:xdigit:]]hex digit (same as [0-9A-Fa-f])
$$$perl-character-classes$$$Supported Perl Character Classes
\ddigits (same as [0-9])
\Dnot digits (same as [^0-9])
\swhitespace (same as [\t\n\f\r ])
\Snot whitespace (same as [^\t\n\f\r ])
\wword characters (same as [0-9A-Za-z_])
\Wnot word characters (same as [^0-9A-Za-z_])