nano SIEM
Search Commands

regex

Supported in:Self-hosted

Keep or drop rows by matching a field against a regular expression. Shorthand for a where regex filter.

Use regex to keep rows whose field matches a regular expression. You can use != to drop matching rows.

Syntax

... | regex <field>="<pattern>"
... | regex <field>!="<pattern>"
... | regex "<pattern>"
ArgumentDefaultDescription
fieldmessageField to test. With no field, regex tests message.
= / !== keeps matching rows; != drops them.
patternRegular expression in double quotes (RE2 syntax).

How it works

  • regex f="p" is the same filter as where f=~"p", and regex f!="p" is the same as where f!~"p". See where.
  • The match is unanchored (it can match anywhere in the value) and case-insensitive. Add ^ and $ to anchor.
  • regex f!="p" also drops rows where f is null.
  • To extract text into new fields, use rex. regex only filters.

For a case-sensitive match, use the match() function in where:

class_uid=1007 | where match(process.name, "^PowerShell") | table time, device.hostname, process.name

Examples

Files created with an executable or script extension:

class_uid=1001 | regex file.name="\.(exe|dll|ps1|bat|vbs|js|hta)$" | stats count by file.name, device.hostname

PowerShell download cradles:

class_uid=1007 process.name="powershell.exe" | regex process.cmd_line="invoke-(expression|webrequest)|downloadstring|iex\s*\(" | table time, device.hostname, actor.user.name, process.cmd_line

Requests from clients that aren't browsers:

class_uid=4002 | regex http_request.user_agent!="mozilla" | stats count by http_request.user_agent | sort -count

Drop static assets from proxy traffic:

metadata.log_source=conduit_proxy | regex http_request.url.path!="\.(css|js|png|jpg|gif|svg|woff2?)$" | stats count by http_request.url.hostname

Test the event message, the default field:

metadata.log_source=otlp_log | regex "timeout|timed out" | head 20

Service accounts that follow a naming pattern:

class_uid=3002 | regex user.name="^svc[-_]" | stats count by user.name, src_endpoint.ip

Notes

  • Filter with an indexed base-search term first (class_uid=1007 process.name="powershell.exe"), then apply regex to the smaller set.
  • A keyword or field="*text*" search is usually faster than a regex when you only need a substring.
  • regex runs as a where filter, so it also works after a nano-side stage (lookup, prevalence, inputlookup, resolve_identity, ai).

What's next

  • where: full expression filters, including =~ and !~
  • rex: extract fields with a regex
  • search: filter with search syntax
  • Functions: match(), regex_extract(), regex_replace()

On this page