Query Details

KQL Regex List

Regex Examples

Query

let RegexTest = @'\W*((?i)Admin(?-i))\W*';
let DataSet = materialize (range numbers from 1 to 10 step 1);
DataSet
| extend StringTest = iff(numbers % 2  == 0, 'Admin', 'User') // Change Admin to a string that should match the RegexTest, change User to a string that should not match the RegexTest
| where StringTest matches regex RegexTest

About this query

Explanation

This document provides a quick reference guide for using regular expressions (regex) in Kusto Query Language (KQL) queries. These regex patterns can be used in detection rules to identify specific patterns in data. Here's a simple breakdown of the key components:

  1. Testing Regex: A sample query is provided to test regex patterns. It checks if a string matches a pattern for the word "Admin" (case insensitive).

  2. IP Address Regex: A pattern to match IPv4 addresses, which are sequences of four numbers separated by dots.

  3. Subnet Regex: A pattern to match IPv4 subnets, which include an IP address followed by a slash and a number.

  4. Domain Regex: A pattern to match domain names, which consist of alphanumeric characters and dots.

  5. File Extension Regex: A pattern to match file extensions, which are sequences of letters following a dot.

  6. String Search Regex: A pattern to search for specific strings like "Domain Admins" in a case-insensitive manner.

  7. Regex Parse Functionality: A pattern to extract text between specific strings, such as extracting a file path from a JSON-like structure.

  8. Regex Between Two Strings: A pattern to find text between two specified strings.

  9. Regex Between Last Char and String: A pattern to find text between the last occurrence of a character and a specified string.

  10. Regex Capture Everything After Char/String: Patterns to capture everything after the last occurrence of a character or a specified string.

  11. Regex Between Word and Special Char: A pattern to find text between a word and a special character.

  12. Regex Between Two Forward Slashes: A pattern to find text between two forward slashes.

  13. File Hash Regex: A pattern to match MD5 file hashes, which are 32-character hexadecimal strings.

  14. Azure ID Regex: A pattern to match Azure IDs, which are UUIDs formatted as a sequence of hexadecimal characters separated by dashes.

Each section includes example queries or references to example queries that demonstrate how to use these regex patterns in practice.

Details

Bert-Jan Pals profile picture

Bert-Jan Pals

Released: December 23, 2024

Tables

DataSetMISPFeedDeviceProcessEvents

Keywords

RegexIPSubnetDomainFileExtensionDeviceProcessEventsHashAzureID

Operators

letmaterializerangefromtostepextendiff%==matchesregexexternaldatawithformatignoreFirstRecordwheredistinct@""\W*(?i)(?-i)[0-9]{13}\./[a-z0-9|-]+\

Actions

GitHub