id stringlengths 7 7 | pattern stringlengths 2 119 | flavor stringclasses 5
values | explanation stringlengths 42 232 | matches listlengths 1 6 | non_matches listlengths 0 5 | difficulty stringclasses 3
values | category stringclasses 8
values | tags listlengths 1 4 |
|---|---|---|---|---|---|---|---|---|
re_0037 | (?:ab)+ | Python | Matches one or more repetitions of the literal string 'ab'. The `(?:...)` is a non-capturing group used to apply the `+` quantifier to the whole sequence 'ab', not just the last character. | [
"ab",
"abab",
"ababab"
] | [
"a",
"b",
"aab",
"abb"
] | intermediate | quantifiers | [
"non-capturing-group",
"group-repetition"
] |
re_0014 | colou?r | Python | Matches both 'color' (US spelling) and 'colour' (UK spelling). The `?` makes the 'u' optional, which is equivalent to the alternation `color|colour`. | [
"color",
"colour",
"favorite color",
"favourite colour"
] | [
"colouur",
"colr"
] | beginner | alternation | [
"optional-char",
"spelling-variant"
] |
re_0199 | \\b(0[1-9]|1[0-2])/(0[1-9]|[12]\\d|3[01])/([12]\\d{3})\\b | Python | Matches a date in MM/DD/YYYY format. Three groups validate month (01β12), day (01β31), and year (1000β2999). Note: does not validate impossible dates like 02/31. | [
"01/15/2024",
"12/31/1999",
"07/04/1776"
] | [
"13/01/2024",
"00/01/2024",
"1/1/2024"
] | advanced | alternation | [
"date-validation",
"MM/DD/YYYY"
] |
re_0122 | ^(?:[01]\d|2[0-3]):[0-5]\d$ | Python | Validates time in HH:MM 24-hour format. Hours 00β09 or 10β19 use `[01]\d`; hours 20β23 use `2[0-3]`. Minutes are 00β59. | [
"00:00",
"09:30",
"23:59",
"12:00"
] | [
"24:00",
"9:60",
"12:60",
"9:30"
] | intermediate | real_world | [
"time-24h",
"HH:MM",
"validation"
] |
re_0062 | [^\S\r\n] | Python | Matches any whitespace character that is NOT a carriage return or newline. Useful for matching horizontal whitespace (spaces and tabs) without consuming line terminators. | [
" ",
"\t",
"\u000b"
] | [
"\n",
"\r",
"a",
"1"
] | advanced | character_classes | [
"horizontal-whitespace",
"line-preservation"
] |
re_0006 | \N{LATIN SMALL LETTER A} | Python | Matches the character named 'LATIN SMALL LETTER A' (i.e., the letter 'a') using Python's `\N{name}` Unicode name escape. A verbose, readable alternative to writing 'a' literally. | [
"a",
"cat",
"alpha"
] | [
"A",
"b",
"1"
] | advanced | special_sequences | [
"unicode-name",
"Python3",
"readability"
] |
re_0065 | ab?c | Python | Matches 'ac' or 'abc'. The `?` quantifier makes the preceding element (`b`) optional β it matches zero or one occurrence. | [
"ac",
"abc",
"xxacyy",
"xxabcyy"
] | [
"abbc",
"adc"
] | beginner | quantifiers | [
"optional",
"zero-or-one"
] |
re_0031 | foo(?!bar) | Python | Negative lookahead: matches 'foo' only when it is NOT immediately followed by 'bar'. | [
"foo",
"foobaz",
"fooX"
] | [
"foobar",
"xxfoobarxx"
] | intermediate | lookarounds | [
"negative-lookahead"
] |
re_0053 | ^\d{10}$ | Python | Matches a string consisting of exactly 10 digits and nothing else. Common for validating 10-digit phone numbers (no spaces or dashes). | [
"1234567890",
"0000000000"
] | [
"123456789",
"12345678901",
"123-456-7890"
] | beginner | quantifiers | [
"exact-length",
"phone-number"
] |
re_0129 | ab*c | Python | Matches 'ac', 'abc', 'abbc', etc. The `*` quantifier allows zero or more occurrences of the preceding element (`b`). | [
"ac",
"abc",
"abbc"
] | [
"aXc",
"abXc"
] | beginner | quantifiers | [
"zero-or-more",
"greedy"
] |
re_0061 | (?i)(error|warning|info|debug):\s*(.*) | Python | Case-insensitive log line parser. Group 1 captures the log level (case-insensitive); group 2 captures the rest of the line as the message. | [
"ERROR: disk full",
"warning: low memory",
"INFO: started"
] | [
"NOTICE: test",
"no colon here"
] | intermediate | groups | [
"log-parsing",
"case-insensitive"
] |
re_0081 | \p{L} | PCRE | Unicode property escape that matches any Unicode letter, regardless of script or case. Available in PCRE, Java, and JavaScript (with the `u` flag). | [
"a",
"Γ©",
"δΈ",
"Ξ±"
] | [
"1",
" ",
"!"
] | advanced | character_classes | [
"unicode-property",
"\\p{L}",
"internationalization"
] |
re_0090 | ^\d{5}(?:-\d{4})?$ | Python | Validates a US ZIP code. Matches exactly 5 digits, with an optional ZIP+4 extension (hyphen followed by 4 digits). | [
"90210",
"10001-1234",
"00000"
] | [
"9021",
"902100",
"90210-123",
"9021A"
] | beginner | real_world | [
"ZIP-code",
"US",
"postal"
] |
re_0192 | \b0b[01]+\b | Python | Matches binary integer literals in Python/C++ (C++14+) style: `0b` prefix followed by one or more binary digits (0 or 1). | [
"0b1010",
"0b0",
"0b11111111"
] | [
"0b",
"0B1010",
"1010",
"0x1010"
] | beginner | real_world | [
"binary-literal",
"number"
] |
re_0038 | \b\w{4}\b | Python | Matches any complete word that is exactly 4 characters long. Word boundaries ensure no shorter or longer words match. | [
"love",
"test",
"code"
] | [
"to",
"hello",
"hi"
] | beginner | quantifiers | [
"exact-word-length",
"word-boundary"
] |
re_0175 | ^$ | Python | Matches an empty string. `^` anchors to the start and `$` anchors to the end with nothing between them. | [
""
] | [
"a",
" ",
"hello"
] | beginner | anchors | [
"empty-string"
] |
re_0110 | \D | Python | Matches any character that is NOT a decimal digit. `\D` is the complement of `\d` and is shorthand for `[^0-9]`. | [
"a",
"!",
" ",
"_"
] | [
"0",
"5",
"9"
] | beginner | character_classes | [
"\\D",
"non-digit"
] |
re_0045 | ^\s*[\w-]+\s*[:=]\s*.+$ | Python | Matches configuration file key-value pairs. The key is word characters or hyphens, the separator is `:` or `=` with optional surrounding spaces, and the value is any non-empty string. | [
"name = Alice",
"max-retries: 5",
"DEBUG=true"
] | [
"= value",
"key",
""
] | intermediate | real_world | [
"config-file",
"key-value",
"INI"
] |
re_0016 | (?:(\d+)\.)?(\d+) | Python | Matches either a plain integer (group 2 only) or a two-part version like '1.5' (group 1 = major, group 2 = minor). The outer non-capturing group makes the first part optional. | [
"42",
"1.5",
"10.3"
] | [
"1.2.3",
"abc"
] | intermediate | groups | [
"optional-group",
"version-like"
] |
re_0198 | \\u03B1 | JavaScript | In JavaScript, `\uNNNN` matches a Unicode character by its four-hex-digit code point. U+03B1 is the Greek lowercase letter alpha: Ξ±. | [
"Ξ±",
"Ξ±Ξ²Ξ³"
] | [
"a",
"alpha",
"03B1"
] | intermediate | special_sequences | [
"unicode-escape",
"Greek",
"JavaScript"
] |
re_0003 | \\t | Python | Matches a horizontal tab character (ASCII 0x09). Useful for parsing tab-separated values (TSV) or detecting indentation. | [
"\thello",
"col1\tcol2"
] | [
" ",
"t",
"\\t"
] | beginner | special_sequences | [
"tab",
"TSV",
"whitespace"
] |
re_0134 | [^aeiou] | Python | Matches any single character that is NOT a lowercase vowel. A `^` at the start of a character class negates it. | [
"b",
"1",
"Z",
"!"
] | [
"a",
"e",
"i",
"o",
"u"
] | beginner | character_classes | [
"negated-class",
"consonant"
] |
re_0161 | \*\*(.+?)\*\*|__(.+?)__ | Python | Matches Markdown bold text β either double-asterisk or double-underscore delimiters. Lazy quantifier prevents over-matching. Group 1 or 2 (whichever matched) contains the bold text. | [
"**bold**",
"__also bold__",
"text **bold** text"
] | [
"*italic*",
"_italic_",
"**unclosed"
] | intermediate | real_world | [
"Markdown",
"bold",
"emphasis"
] |
re_0043 | \e | PCRE | Matches the escape character (ASCII 0x1B, ESC). Used in terminal control sequences (ANSI escape codes) and binary protocol parsing. `\e` is available in PCRE and some other engines but not Python's `re`. | [
"\u001b",
"\u001b[31m"
] | [
"e",
"\\e",
"\u0000"
] | intermediate | special_sequences | [
"escape-char",
"ANSI",
"terminal"
] |
re_0121 | (?i)^[a-z]{2,}:// | Python | Matches any URL scheme (two or more letters followed by `://`). Case-insensitive. Broader than checking only http/https β catches ftp, smtp, ws, wss, etc. | [
"http://",
"HTTPS://",
"ftp://",
"ws://"
] | [
"http:/",
"://foo",
"12://"
] | beginner | real_world | [
"URL-scheme",
"protocol"
] |
re_0179 | \\((?:[^)(]|(?R))*\\) | PCRE | Recursive pattern using `(?R)` (PCRE only). Matches balanced parentheses of arbitrary nesting depth. `(?R)` recursively inserts the entire pattern, allowing it to handle nested groups. | [
"()",
"(hello)",
"((a)(b))",
"(1(2(3)))"
] | [
"(unclosed",
"unmatched)",
"(a(b)"
] | advanced | groups | [
"recursive",
"balanced-parens",
"PCRE"
] |
re_0178 | \\p{Han} | PCRE | Unicode script property matching any CJK Unified Ideograph in the Han script. Useful for detecting or extracting Chinese, Japanese Kanji, or Korean Hanja characters. | [
"δΈ",
"ζ",
"ζΌ’ε",
"ε¦"
] | [
"a",
"1",
"γ²",
"κ°"
] | advanced | special_sequences | [
"unicode-script",
"CJK",
"Han"
] |
re_0205 | a{2,4}? | Python | Lazy range quantifier. Matches the minimum number of 'a's needed (2) rather than the greedy maximum (4). In 'aaaa', a greedy `{2,4}` matches all 4; this lazy version matches only 2. | [
"aa",
"aaa",
"aaaa"
] | [
"a",
""
] | intermediate | quantifiers | [
"lazy-range",
"minimal-match"
] |
re_0128 | ^hello world$ | Python | Matches the exact string 'hello world' with nothing before or after it. Both `^` and `$` ensure the full string is consumed. | [
"hello world"
] | [
"hello worlds",
"say hello world",
"hello world!"
] | beginner | anchors | [
"exact-match",
"full-string"
] |
re_0166 | (\\w+)\\s+(\\w+)(?:,\\s*(\\w+))? | Python | Parses a name pattern: required first and last name (groups 1 and 2), with an optional suffix like 'Jr.' or 'III' (group 3). The suffix group is non-capturing outer group with a capturing inner group. | [
"John Smith",
"Jane Doe, Jr",
"Robert Brown, III"
] | [
"John",
"Smith Jr"
] | intermediate | real_world | [
"name-parsing",
"optional-suffix"
] |
re_0004 | a{3,} | Python | Matches 3 or more consecutive 'a' characters. The `{n,}` form specifies a minimum with no upper bound. | [
"aaa",
"aaaa",
"aaaaaaa"
] | [
"aa",
"a",
""
] | beginner | quantifiers | [
"minimum-count",
"unbounded"
] |
re_0080 | ^(https?)://([\w.-]+)(/.*)?\s*$ | Python | Structured URL parser with three capturing groups: group 1 (scheme: http or https), group 2 (hostname), group 3 (optional path). | [
"http://example.com",
"https://foo.bar/path/to/page"
] | [
"ftp://example.com",
"example.com"
] | intermediate | groups | [
"URL-parsing",
"scheme",
"host",
"path"
] |
re_0133 | world$ | Python | Matches 'world' only when it appears at the very end of the string. The dollar `$` is the end-of-string anchor. | [
"hello world",
"world",
"my world"
] | [
"worlds",
"world!",
"worldwide"
] | beginner | anchors | [
"dollar",
"end-of-string"
] |
re_0074 | a{3} | Python | Matches exactly three consecutive 'a' characters. Curly-brace quantifiers `{n}` specify an exact repetition count. | [
"aaa",
"aaaa",
"baaac"
] | [
"aa",
"a",
"ab"
] | beginner | quantifiers | [
"exact-count",
"repetition"
] |
re_0103 | \b\d+\s*(?:px|em|rem|%|vh|vw|pt|cm|mm|in)\b | Python | Matches CSS dimension values: a number followed by a CSS unit (px, em, rem, %, vh, vw, pt, cm, mm, in). Word boundary prevents partial matches. | [
"16px",
"1.5em",
"100%",
"50vh",
"2rem"
] | [
"16",
"px",
"100 foo"
] | intermediate | real_world | [
"CSS",
"dimensions",
"units"
] |
re_0158 | (?:\d{1,3}\.){3}\d{1,3} | Python | Simplified IPv4 pattern using a repeated non-capturing group. Matches three groups of 1β3 digits followed by dots, then a final group. Does not validate octet values (0β255). | [
"192.168.0.1",
"10.0.0.255"
] | [
"192.168.0",
"192.168.0.1.2"
] | intermediate | quantifiers | [
"IPv4",
"group-repetition"
] |
re_0079 | ^\s*$ | Python | Matches a string that consists entirely of zero or more whitespace characters (spaces, tabs, newlines). Useful for detecting blank lines. | [
"",
" ",
"\t\t",
" \n "
] | [
"a",
" x ",
"hello"
] | beginner | anchors | [
"blank-line",
"whitespace"
] |
re_0176 | ^hello | Python | Matches the string 'hello' only when it appears at the very start of the string (or line in MULTILINE mode). The caret `^` is the start-of-string anchor. | [
"hello world",
"hello",
"hello!"
] | [
"say hello",
" hello",
"world hello"
] | beginner | anchors | [
"caret",
"start-of-string"
] |
re_0163 | (['\"]).*?\\1 | Python | Matches a single-quoted or double-quoted string. Group 1 captures the opening quote character, and `\1` backreference ensures the closing quote matches the same character. | [
"\"hello\"",
"'world'"
] | [
"\"unclosed",
"mismatch"
] | advanced | groups | [
"backreference",
"quote-matching"
] |
re_0010 | a*+ | PCRE | Possessive quantifier (PCRE only). Like `a*` but once characters are matched, the engine never backtracks into them. Improves performance and can prevent catastrophic backtracking. | [
"",
"a",
"aaa",
"aaabbb"
] | [] | advanced | quantifiers | [
"possessive",
"no-backtrack",
"PCRE"
] |
re_0013 | ^.{8,}$ | Python | Matches any string that is at least 8 characters long. A simple minimum-length check, often used as the most basic password length requirement. | [
"password",
"12345678",
"Hello World"
] | [
"pass",
"1234567"
] | beginner | real_world | [
"length-validation",
"password"
] |
re_0039 | ^\\s*//.*$ | Python | Matches single-line comments in C-style languages (C, C++, Java, JavaScript, etc.). `\s*` allows optional leading whitespace, `//` starts the comment, and `.*` consumes the rest of the line. | [
"// comment",
" // indented",
" // x = 5"
] | [
"/* block */",
"code // not full line match"
] | beginner | real_world | [
"comment",
"C-style",
"code-parsing"
] |
re_0048 | (?m)^\d+ | Python | With MULTILINE mode enabled (`(?m)`), `^` matches at the start of every line, not just the start of the string. Matches one or more digits at the start of any line. | [
"123 abc\n456 def",
"99 bottles"
] | [
"abc 123",
" 42"
] | intermediate | anchors | [
"multiline",
"line-start"
] |
re_0046 | (?:(?:\r\n|\r|\n)(?!\s)) | Python | Matches a line break (CRLF, CR, or LF) that is NOT followed by whitespace β i.e., a 'hard' paragraph break between non-indented lines. | [
"\r\nHello",
"\nFoo",
"\rBar"
] | [
"\n indented",
"\r\n\t"
] | advanced | real_world | [
"line-break",
"paragraph",
"CRLF"
] |
re_0085 | (?=\S)(?=\D) | Python | Matches a position that is both non-whitespace and non-digit (i.e., a letter or punctuation). Two lookaheads at the same position combine with logical AND. | [
"a",
"!",
"Z",
"."
] | [
" ",
"5",
"\t"
] | advanced | lookarounds | [
"combined-lookaheads",
"AND-logic"
] |
re_0101 | (?<!\\)\$\{(\w+)\} | Python | Matches shell variable expansions `${VAR}` that are not escaped by a preceding backslash. Negative lookbehind prevents matching `\${VAR}`. | [
"${HOME}",
"${PATH}"
] | [
"\\${HOME}",
"$HOME",
"${1invalid}"
] | advanced | lookarounds | [
"shell-variable",
"escape-aware",
"negative-lookbehind"
] |
re_0077 | [^\r\n] | Python | Matches any character except carriage return and newline. Equivalent to `.` (which by default excludes newlines), but explicit about excluding both CR and LF. | [
"a",
" ",
"!",
"\t"
] | [
"\n",
"\r"
] | intermediate | character_classes | [
"non-newline",
"line-char"
] |
re_0191 | (?i)^[a-z0-9._%+\\-]+@[a-z0-9.\\-]+\\.[a-z]{2,4}$ | Go | Email validator as used with Go's `regexp` package. Go uses RE2 syntax, which does not support lookaheads or backreferences. `(?i)` provides case-insensitive matching. | [
"user@example.com",
"USER@EXAMPLE.COM"
] | [
"@example.com",
"user@"
] | intermediate | real_world | [
"email",
"Go",
"RE2"
] |
re_0078 | ab+c | Python | Matches 'abc', 'abbc', 'abbbc', etc. The `+` quantifier requires one or more occurrences of the preceding element (`b`). | [
"abc",
"abbc",
"abbbc"
] | [
"ac",
"aXc"
] | beginner | quantifiers | [
"one-or-more",
"greedy"
] |
re_0070 | ^[^<>]*$ | Python | Matches a string that contains no angle brackets. A simple way to reject strings that might contain HTML or XML tags without a full parser. | [
"hello world",
"1 + 2 = 3",
"plain text"
] | [
"<b>bold</b>",
"a<b"
] | beginner | real_world | [
"sanitization",
"no-HTML",
"input-validation"
] |
re_0067 | ^\[(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})\]\s+\[(\w+)\]\s+(.+)$ | Python | Parses a structured log line format `[TIMESTAMP] [LEVEL] MESSAGE`. Group 1: ISO 8601 timestamp, Group 2: log level, Group 3: message text. | [
"[2024-01-15T09:30:00] [ERROR] Disk full",
"[2024-06-01T00:00:00] [INFO] Started"
] | [
"2024-01-15 ERROR Disk full",
"[bad-ts] [ERROR] msg"
] | intermediate | real_world | [
"log-parsing",
"timestamp",
"structured-log"
] |
re_0017 | ^>\s?(.*)$ | Python | Matches a Markdown blockquote line. The `>` character (optionally followed by one space) starts the line; group 1 captures the quoted text. | [
"> quoted",
">no space",
"> multi word"
] | [
">> nested",
"quoted without prefix"
] | beginner | real_world | [
"Markdown",
"blockquote"
] |
re_0132 | \d$ | Python | Matches any string that ends with a digit. | [
"hello1",
"test42",
"99"
] | [
"hello",
"1abc",
"1 "
] | beginner | anchors | [
"end-digit"
] |
re_0096 | ^[A-Z]{1,2}\d{1,4}[A-Z]{0,2}\s?\d[A-Z]{2}$ | Python | Validates a UK postcode format. One or two uppercase letters, 1β4 digits, optional 1β2 letters, optional space, one digit, and two uppercase letters. | [
"SW1A 2AA",
"EC1A1BB",
"W1A0AX",
"M1 1AE"
] | [
"12345",
"SW1A 2AAA",
"sw1a 2aa"
] | advanced | real_world | [
"postcode",
"UK",
"validation"
] |
re_0001 | <(b|i|u|strong|em)>.*?</\\1> | Python | Matches common inline HTML tags with their content. Group 1 captures the opening tag name; `\1` backreference ensures the closing tag matches. The `.*?` lazily matches any content. | [
"<b>bold</b>",
"<em>emphasis</em>",
"<strong>!</strong>"
] | [
"<div>block</div>",
"<b>no close",
"<i>mismatch</b>"
] | advanced | alternation | [
"HTML-tag",
"backreference",
"inline-tags"
] |
re_0112 | \\d+(?:[,_]\\d+)*(?:\\.\\d+)? | Java | Java 7+ allows underscores in numeric literals (e.g. `1_000_000`). This pattern matches integers or decimals optionally containing underscores or commas as thousands separators. | [
"1000",
"1,000",
"1_000_000",
"3.14"
] | [
"_1000",
"1000_",
"1__000"
] | advanced | real_world | [
"Java",
"numeric-literal",
"Java7"
] |
re_0011 | https?://(?:www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*) | Python | General-purpose URL matcher. Handles http and https, optional www, domain name, TLD (1β6 chars), and optional path/query/fragment. | [
"https://example.com",
"http://www.foo.bar/path?q=1#anchor"
] | [
"ftp://example.com",
"example.com",
"not a url"
] | advanced | real_world | [
"URL",
"web"
] |
re_0114 | @\\w+(?:\\([^)]*\\))? | Java | Matches Java annotations. An `@` followed by a word (annotation name), optionally followed by arguments in parentheses. | [
"@Override",
"@SuppressWarnings(\"unchecked\")",
"@Test"
] | [
"@ override",
"Override",
"@"
] | intermediate | real_world | [
"Java",
"annotation",
"code-parsing"
] |
re_0136 | \b[A-Z][A-Z0-9]{1,7}\b | Python | Matches stock ticker symbols: 1β8 uppercase letters/digits, starting with a letter. Loose match β does not validate against actual exchanges. | [
"AAPL",
"GOOGL",
"TSLA",
"BRK",
"SPY"
] | [
"aapl",
"TOOLONGSTICKER",
"1NVALID"
] | beginner | real_world | [
"stock-ticker",
"finance"
] |
re_0113 | \p{Lu} | JavaScript | Unicode property escape matching any uppercase letter (`Lu` = Letter, uppercase). Requires the JavaScript `/u` flag or PCRE `(*UTF)` mode. | [
"A",
"Γ",
"Ξ©",
"Π―"
] | [
"a",
"Γ©",
"1",
" "
] | advanced | character_classes | [
"unicode-property",
"uppercase",
"JavaScript"
] |
re_0022 | \\$\\{([^}]+)\\} | Python | Matches template literal placeholders in the form `${...}`. Group 1 captures the expression inside the braces. Used in JavaScript template strings or shell variable expansion. | [
"${name}",
"${user.firstName}",
"${count + 1}"
] | [
"$name",
"{name}",
"$(name)"
] | intermediate | real_world | [
"template-literal",
"interpolation",
"JavaScript"
] |
re_0137 | (?=(\\d+))\\1 | Python | Lookahead used as a capturing trick. The lookahead `(?=(\d+))` captures digits into group 1 without consuming them; `\1` then matches them again. This forces the engine to find repeated digit sequences. | [
"123123",
"4545",
"99"
] | [
"123",
"1234"
] | advanced | groups | [
"lookahead-capture",
"atomic-trick"
] |
re_0201 | [a-z0-9_-] | Python | Matches a single character that is a lowercase letter, digit, underscore, or hyphen. This is a common pattern for validating URL slugs. | [
"a",
"3",
"_",
"-",
"z9"
] | [
"A",
"!",
" ",
"@"
] | beginner | character_classes | [
"slug",
"url",
"hyphen-literal"
] |
re_0111 | ^([A-HJ-NP-Z])(\d)([A-HJ-NP-Z\d])(\d)([A-HJ-NP-Z\d])(\d)$ | Python | Validates a Canadian postal code. Alternates letters (excluding D, F, I, O, Q, U) and digits. Letters cannot be D, F, I, O, Q, or U. Example: 'K1A 0B1' without the space. | [
"K1A0B1",
"V6B4N7"
] | [
"D1A0B1",
"K1A 0B1",
"K1A0B"
] | advanced | real_world | [
"postal-code",
"Canada",
"validation"
] |
re_0149 | ^[\da-fA-F]{1,4}(?::[\da-fA-F]{0,4}){2,7}$ | Python | Simplified IPv6 address matcher (not fully RFC 5952 compliant). Matches 2β8 groups of 1β4 hex digits separated by colons. Does not handle `::` abbreviation. | [
"2001:0db8:85a3:0000:0000:8a2e:0370:7334"
] | [
"::1",
"2001:db8::1",
"gggg::1"
] | advanced | real_world | [
"IPv6",
"network",
"validation"
] |
re_0172 | (?x) # verbose mode\n^ # start\n\\d+ # digits\n$ # end | Python | Verbose mode (`(?x)` or `re.VERBOSE` flag). Allows whitespace and comments inside the pattern, making complex regexes more readable. Literal spaces must be escaped or inside `[]`. | [
"123",
"0",
"9999"
] | [
"abc",
"1 2",
""
] | advanced | special_sequences | [
"verbose-mode",
"comments",
"readability"
] |
re_0033 | \d | Python | Matches any single decimal digit (0β9). `\d` is shorthand for the character class `[0-9]`. | [
"0",
"5",
"9",
"abc1"
] | [
"a",
" ",
".",
"-"
] | beginner | character_classes | [
"\\d",
"digit",
"shorthand"
] |
re_0157 | [[:punct:]] | PCRE | POSIX character class matching any punctuation character: `!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~` and backtick. | [
"!",
".",
",",
"?",
"@",
"_"
] | [
"a",
"1",
" "
] | intermediate | character_classes | [
"POSIX",
"punctuation"
] |
re_0126 | ^[0-9a-f]{32}$ | Python | Validates an MD5 hash string: exactly 32 lowercase hexadecimal characters. | [
"d41d8cd98f00b204e9800998ecf8427e",
"098f6bcd4621d373cade4e832627b4f6"
] | [
"D41D8CD98F00B204E9800998ECF8427E",
"d41d8cd98f00b204e9800998ecf8427",
"zz"
] | beginner | real_world | [
"MD5",
"hash",
"validation"
] |
re_0125 | \s | Python | Matches any whitespace character: space, tab (`\t`), newline (`\n`), carriage return (`\r`), form feed (`\f`), or vertical tab (`\v`). | [
" ",
"\t",
"\n",
"\r"
] | [
"a",
"1",
"_",
"!"
] | beginner | character_classes | [
"\\s",
"whitespace"
] |
re_0147 | \W | Python | Matches any non-word character β the complement of `\w`. Equivalent to `[^a-zA-Z0-9_]`. | [
" ",
"!",
"-",
"@",
"."
] | [
"a",
"Z",
"5",
"_"
] | beginner | character_classes | [
"\\W",
"non-word"
] |
re_0105 | [a-zA-Z] | Python | Matches any single ASCII letter, uppercase or lowercase. Hyphens inside character classes denote ranges when placed between two characters. | [
"a",
"Z",
"m",
"Q"
] | [
"1",
"!",
" ",
"_"
] | beginner | character_classes | [
"letter",
"range"
] |
re_0086 | (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) | JavaScript | Named capturing groups using `(?<name>...)` syntax (ECMAScript 2018+). Captures an ISO date into groups accessible via `match.groups.year`, etc. | [
"2024-01-15",
"1999-12-31"
] | [
"24-1-15",
"2024/01/15"
] | intermediate | groups | [
"named-group",
"JavaScript",
"ES2018"
] |
re_0127 | [A-Z] | JavaScript | In JavaScript, `\u` followed by four hex digits matches a Unicode code point. This class matches uppercase ASCII letters A (U+0041) through Z (U+005A). | [
"A",
"M",
"Z"
] | [
"a",
"1",
"Γ"
] | intermediate | character_classes | [
"unicode",
"hex-codepoint",
"JavaScript"
] |
re_0020 | (?:19|20)\\d\\d | Python | Matches a four-digit year in the range 1900β2099. The alternation `(?:19|20)` ensures the first two digits are either '19' or '20', followed by any two digits. | [
"1900",
"2024",
"2099",
"in 2025"
] | [
"1899",
"2100",
"99",
"20AB"
] | intermediate | alternation | [
"year",
"range-validation"
] |
re_0015 | <!--[\\s\\S]*?--> | Python | Lazily matches HTML comments including their content, even across multiple lines. `[\s\S]*?` matches any character including newlines (since `.` does not match `\n` by default). | [
"<!-- comment -->",
"<!-- multi\nline\ncomment -->"
] | [
"<tag>",
"// not HTML comment"
] | intermediate | real_world | [
"HTML-comment",
"multiline",
"parsing"
] |
re_0182 | \bhello\b | Python | Matches the word 'hello' as a complete word. The `\b` word-boundary anchor prevents matching inside longer words like 'helloworld'. | [
"hello",
"say hello!",
"hello world"
] | [
"helloworld",
"helloed",
"ohello"
] | beginner | anchors | [
"word-boundary"
] |
re_0145 | a{2,4} | Python | Matches between 2 and 4 consecutive 'a' characters, greedily consuming as many as possible (up to 4). | [
"aa",
"aaa",
"aaaa",
"baaaac"
] | [
"a",
"aaaaa"
] | beginner | quantifiers | [
"range-count",
"greedy"
] |
re_0139 | ^[2-9]\d{2}[2-9]\d{6}$ | Python | Validates a North American 10-digit phone number (NANP) without separators. First and fourth digits must be 2β9 (area code and exchange codes cannot start with 0 or 1). | [
"2125551234",
"8005551234"
] | [
"1125551234",
"0125551234",
"21255512345"
] | intermediate | real_world | [
"phone-number",
"NANP",
"US"
] |
re_0066 | (?<=\\$)\\d+\\.\\d{2} | Python | Matches a dollar amount (digits.cents) only when immediately preceded by a dollar sign. Lookbehind requires fixed-width assertion. | [
"$19.99",
"$0.50",
"price: $100.00"
] | [
"19.99",
"β¬19.99",
"$ 19.99"
] | intermediate | lookarounds | [
"positive-lookbehind",
"price",
"fixed-width"
] |
re_0102 | ^func\\s+(\\w+)\\( | Go | Matches the start of a Go function declaration. Captures the function name in group 1. Assumes no receiver (non-method function). | [
"func foo(",
"func myHandler(",
"func FooBar("
] | [
"var foo",
"type Foo",
"//func foo("
] | intermediate | real_world | [
"Go",
"function",
"code-parsing"
] |
re_0123 | (\w+)\s*:\s*(\w+(?:\s+\w+)*) | Python | Parses a simple key: value pair where the key is a single word and the value is one or more words. Captures key in group 1 and value in group 2. | [
"name: Alice",
"status: in progress",
"type: error"
] | [
"no-colon",
": no key",
"key:"
] | intermediate | groups | [
"key-value",
"config-parsing"
] |
re_0047 | ^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$ | Python | Validates a MAC address in colon-separated hex format (e.g. 00:1A:2B:3C:4D:5E). Five groups of two hex digits followed by colons, then a final pair. | [
"00:1A:2B:3C:4D:5E",
"ff:ff:ff:ff:ff:ff",
"00:00:00:00:00:00"
] | [
"00-1A-2B-3C-4D-5E",
"001A2B3C4D5E",
"00:1A:2B:3C:4D"
] | intermediate | real_world | [
"MAC-address",
"network"
] |
re_0107 | (?#this is a comment)\d+ | Python | Inline comment using `(?#...)`. The comment is completely ignored by the regex engine. Useful for annotating pattern segments without enabling full verbose mode. | [
"123",
"0",
"9999"
] | [
"abc",
""
] | intermediate | special_sequences | [
"inline-comment",
"readability"
] |
re_0165 | (?<=@)\w+ | Python | Extracts the username domain part of an email β the word characters immediately following the @ sign. | [
"user@gmail",
"name@company"
] | [
"user",
"gmail.com"
] | intermediate | lookarounds | [
"email",
"domain-extraction"
] |
re_0055 | [ -~] | JavaScript | Matches any printable ASCII character (code points 0x20 to 0x7E, i.e., space through tilde). Uses Unicode escape syntax available in JavaScript. | [
"a",
"Z",
"1",
"!",
" ",
"~"
] | [
"\u0000",
"\u001f",
"",
"Γ©"
] | intermediate | character_classes | [
"printable-ASCII",
"unicode-escape",
"JavaScript"
] |
re_0143 | \d*\.?\d+ | Python | Matches an integer or decimal number. `\d*` allows zero or more leading digits; `\.?` makes the decimal point optional; `\d+` requires at least one digit after (or as the whole number). | [
"3.14",
"42",
".5",
"0.001"
] | [
".",
"abc",
"1."
] | intermediate | quantifiers | [
"decimal",
"number",
"optional-point"
] |
re_0148 | `[^`]+` | Python | Matches inline code spans in Markdown: text enclosed in single backticks. Does not handle multi-backtick fences. | [
"`code`",
"`x = 1`",
"use `foo()` here"
] | [
"``double``",
"no backtick",
"`unclosed"
] | beginner | real_world | [
"Markdown",
"inline-code"
] |
re_0131 | \\N{SNOWMAN} | Python | Python 3 regex extension: matches the Unicode character named 'SNOWMAN' (U+2603, β). `\N{name}` lets you reference characters by their official Unicode name for readability. | [
"β",
"Hello β World"
] | [
"snowman",
"snow",
"2603"
] | advanced | special_sequences | [
"unicode-name",
"Python3"
] |
re_0120 | ^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$ | Python | IBAN (International Bank Account Number) basic format validator. Starts with 2 uppercase country code letters, 2 check digits, then 1β30 alphanumeric characters. | [
"GB29NWBK60161331926819",
"DE89370400440532013000"
] | [
"gb29NWBK60161331926819",
"123NWBK60161331926819"
] | advanced | real_world | [
"IBAN",
"banking",
"finance"
] |
re_0153 | <!--[\s\S]*?-->|<[^>]+> | Python | Strips HTML: matches either HTML comments (`<!--...-->`) or any HTML tag (`<...>`). Replace matches with empty string to extract plain text (basic approach, not parser-safe). | [
"<!-- hi -->",
"<div>",
"<a href='x'>",
"<br/>"
] | [
"plain text",
"<<not a tag>>"
] | intermediate | real_world | [
"HTML-strip",
"text-extraction"
] |
re_0146 | \0 | Python | Matches the null byte character (ASCII 0x00, NUL). Useful for parsing binary data or detecting null-terminated strings. | [
"\u0000",
"hello\u0000world"
] | [
"0",
"null",
"\\0"
] | intermediate | special_sequences | [
"null-byte",
"binary"
] |
re_0034 | ^\d | Python | Matches any string that starts with a digit. The `^` anchor ensures the digit is the very first character. | [
"1 hello",
"42",
"0abc"
] | [
"hello",
" 1",
"abc1"
] | beginner | anchors | [
"start-digit"
] |
re_0184 | cat|dog | Python | Alternation: matches either 'cat' or 'dog'. The `|` operator is the regex OR β the engine tries the left alternative first, then the right. | [
"cat",
"dog",
"I have a cat",
"my dog"
] | [
"cats",
"dogs",
"fish"
] | beginner | alternation | [
"or",
"alternatives"
] |
re_0181 | \b(?:0x|0X)[0-9a-fA-F]+\b | Python | Matches C-style hexadecimal integer literals: the prefix `0x` or `0X` followed by one or more hex digits. | [
"0x1F",
"0xFF",
"0XABC123",
"value 0x00"
] | [
"0x",
"ff",
"1F",
"0b1010"
] | intermediate | real_world | [
"hex-literal",
"C-style",
"number"
] |
re_0083 | (?i)\b(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|TRACE)\b\s+(/[^\s]*)\s+HTTP/\d\.\d | Python | Parses an HTTP request line. Captures the HTTP method (group 1 β note: whole match, no specific group here without modification), request path (group 1), and HTTP version. | [
"GET /index.html HTTP/1.1",
"POST /api/data HTTP/2.0"
] | [
"GET /index.html",
"GET HTTP/1.1"
] | advanced | real_world | [
"HTTP",
"request-line",
"parsing"
] |
re_0180 | [Yy]es|[Nn]o | Python | Matches 'Yes', 'yes', 'No', or 'no'. Alternation of two character-class patterns allows case-insensitive matching of specific capitalization forms without the `(?i)` flag. | [
"Yes",
"yes",
"No",
"no"
] | [
"YES",
"NO",
"maybe",
"yess"
] | beginner | alternation | [
"yes-no",
"boolean",
"capitalization"
] |
re_0064 | \p{P} | PCRE | Unicode property escape matching any Unicode punctuation character. Covers punctuation from all scripts, not just ASCII. | [
".",
",",
"οΌ",
"γ",
"Β«"
] | [
"a",
"1",
" "
] | advanced | character_classes | [
"unicode-property",
"punctuation",
"PCRE"
] |
re_0084 | [A-Fa-f0-9] | Python | Matches a single hexadecimal digit β any character in the ranges A-F, a-f, or 0-9. Commonly used to validate hex color codes or hash strings. | [
"a",
"F",
"0",
"9",
"c"
] | [
"g",
"G",
"x",
"!"
] | beginner | character_classes | [
"hex",
"hexadecimal"
] |
re_0170 | (foo)(bar) | Python | Two consecutive capturing groups. Group 1 captures 'foo' and group 2 captures 'bar'. Each `(...)` creates a numbered capture group accessible via match.group(1), match.group(2), etc. | [
"foobar",
"xxfoobarxx"
] | [
"foo",
"bar",
"barfoo"
] | beginner | groups | [
"capturing-group",
"multiple-groups"
] |
End of preview. Expand in Data Studio
Regex Explanations
A synthetic dataset of 205 curated regex patterns paired with plain-English explanations, match/non-match examples, and rich metadata. Designed for training and evaluating models that explain or generate regular expressions.
Dataset Summary
Each record maps a regular expression pattern to:
- A detailed plain-English explanation of what it matches and why
- Lists of positive examples (strings that match)
- Lists of negative examples (strings that do not match)
- Metadata: regex flavor, difficulty level, category, and tags
The dataset covers 8 pattern categories across 5 regex flavors, hand-authored for accuracy and clarity.
Supported Tasks
- Regex explanation generation (
pattern β explanation): train seq2seq or LLM models to explain what a regex does - Regex synthesis (
explanation β pattern): generate a regex from a plain-English description - Regex classification: predict difficulty, category, or flavor from the pattern
- Code education: teach regex concepts with worked examples
Dataset Structure
regex-explanations/
βββ train.jsonl / train.parquet (164 examples, 80%)
βββ validation.jsonl / validation.parquet (20 examples, 10%)
βββ test.jsonl / test.parquet (21 examples, 10%)
Fields
| Field | Type | Description |
|---|---|---|
id |
string | Unique identifier (re_XXXX) |
pattern |
string | The regex pattern as written |
flavor |
string | Regex engine flavor: Python, JavaScript, PCRE, Go, Java |
explanation |
string | Plain-English explanation of what the pattern matches and why |
matches |
list[string] | Example strings that the pattern matches |
non_matches |
list[string] | Example strings that the pattern does NOT match |
difficulty |
string | beginner, intermediate, or advanced |
category |
string | Pattern category (see below) |
tags |
list[string] | Concept tags (e.g., lookahead, word-boundary, email) |
Categories
| Category | Count | Description |
|---|---|---|
anchors |
15 | ^, $, \b, \A, \Z, \G, lookbehind anchors |
character_classes |
25 | [...], \d, \w, \s, POSIX, Unicode properties |
quantifiers |
22 | *, +, ?, {n,m}, lazy, possessive |
groups |
21 | Capturing, non-capturing, named, backreferences, atomic |
lookarounds |
17 | Positive/negative lookaheads and lookbehinds |
alternation |
16 | |, branch reset groups |
special_sequences |
18 | \n, \t, \x, \u, \p{}, verbose mode |
real_world |
71 | Email, URL, IP, dates, phone numbers, code patterns, Markdown |
Difficulty Distribution
| Difficulty | Count | % |
|---|---|---|
beginner |
62 | 30% |
intermediate |
85 | 41% |
advanced |
58 | 28% |
Regex Flavor Distribution
| Flavor | Count |
|---|---|
Python |
174 |
PCRE |
20 |
JavaScript |
6 |
Go |
3 |
Java |
2 |
Sample Records
| Pattern | Flavor | Difficulty | Category | Explanation (truncated) | Matches | Non-Matches |
|---|---|---|---|---|---|---|
^!\[([^\]]*)\]\(([^)]+)\)$ |
Python | intermediate | real_world | Matches a standalone Markdown image: . Group 1 captures the al... |
, ,  |
[link](url), ![no-close(img.png) |
\d{1,3}(\.\d{1,3}){3} |
Python | intermediate | quantifiers | Rough pattern for an IPv4 address. Matches 1β3 digits, followed by exactly three... | 192.168.1.1, 10.0.0.255, 1.2.3.4 |
192.168, 1.2.3 |
^[\\w.+-]+@[\\w-]+\\.[\\w.-]+$ |
Python | intermediate | real_world | Simplified email address validator. Matches a local part (word chars, dots, plus... | user@example.com, user.name+tag@sub.domain.org |
@example.com, user@ |
Generation Methodology
All records are hand-authored by the SalutefaceAAC agent. Each pattern was:
- Written with a specific teaching goal in mind (one concept per pattern where possible)
- Given a detailed explanation covering the syntax mechanics and use case
- Paired with concrete match/non-match examples for immediate verification
- Labeled with structured metadata to enable filtered fine-tuning
No LLM was used to generate the regex patterns or their explanations β this ensures technical accuracy and avoids hallucinated regex behavior.
Limitations
- Patterns marked
PCREorJavaare not runnable with Python'sremodule (useregexpackage or appropriate engine) - The
real_worldpatterns are heuristic validators β they trade RFC compliance for readability and simplicity non_matcheslists are illustrative, not exhaustive- Patterns that match the empty string may have empty
non_matcheslists - Advanced PCRE features (recursive patterns, branch reset groups) cannot be tested with standard Python tooling
License
Apache 2.0 β free to use for any purpose, commercial or research.
Citation
@dataset{salutefaceaac_regex_explanations_2026,
title = {Regex Explanations},
author = {SalutefaceAAC},
year = {2026},
url = {https://huggingface.co/datasets/SalutefaceAAC/regex-explanations},
note = {Synthetic dataset of 205 hand-authored regex pattern explanations}
}
- Downloads last month
- 47