This function both works as a filter and can extract new fields using a
regular expression. The regular expression can contain one or more named
capturing groups. Fields with the names of the groups will be added to the
" in already quoted strings requires escaping.
This is sometimes necessary when writing regular expressions.
LogScale uses JitRex which closely follows — but does not entirely replicate — the syntax of RE2J regular expressions, which is very close to Java's regular expressions. See Regular Expression Syntax for more information.
To ensure compatibilty, it is recommended to always test your regular expressions inside LogScale, instead of a 3rd party regex tool.
|string||optional[a]||Specifies the field to run the regular expression against.|
|string||optional[a]||Specifies regex modifier flags.|
|Valid Values||Period (.) also includes newline characters|
|Ignore case for matched values|
|Multi-line parsing of regular expressions|
|integer||optional[a]||Defines the maximum number of events to produce. A warning is produced if this limit is exceeded, unless the parameter is specified explicitly.|
|string||required||Specifies a regular expression. The regular expression can contain one or more named capturing groups. Fields with the names of the groups will be added to the events.|
|boolean||optional[a]||If set to true, multiple matches yields multiple events.|
|Valid Values||Match at most one event|
|Match multiple events|
|boolean||optional[a]||Specifies if events not matching the regular expression should be filtered out of the result set.|
|Valid Values||Events not matching the regular expression are not filtered out then the regex matches.|
|Events not matching the regular expression are filtered out of the result set.|
[a] Optional parameters use their default value unless explicitly set
The parameter name for
regex can be omitted; the following forms are equivalent:
regex() provides similar functionality to the
/regex/ syntax, however, the
function searches specific fields (and only
@rawstring by default). In contrast, the
/regex/ syntax searches all sent and
parsed fields and @rawstring.
If you specify a field with the
/regex/ syntax, the search is limited only to those field,
| sessionid = /sess/
Limits the search to only the specified field.
The difference in search scope between the two regex syntax operations
introduces a significant performance difference between the two. Using
regex() searches only the specified field
(@rawstring by default) and can be significantly
more performant than the
/regex/ syntax depending on the
number of fields in the dataset.
When performing queries, the
— used for global, as in repeating — is allowed in a query,
but is not an acceptable option for the
parameter. To use one of the parameters for multiple matches, you should
instead set the
repeat parameter to
For more information, see Global (Repeating) Matches.
Extract the domain name of the http referrer field. Often this field contains a full url, so we can have many different URLs from the same site. In this case we want to count all referrals from the same domain. This will add a field named refdomain to events matching the regular expression.
regex("https?://(www.)?(?<refdomain>.+?)(/ | $)", field=referrer) | groupby(refdomain, function=count()) | sort(field=_count, type=number, reverse=true)
Extract the user id from the url field. New fields are stored in a field named userid.
Show how to escape
" in the regular
expression. This is necessary because the regular expression is itself
in quotes. Extract the user and message from events like:
Peter: "hello" and
Bob: "good morning".
Note that the default flags for a regular expression is no flags, so that:
Is syntactically equivalent to:
When using flags:
Is syntactically equivalent to: