Quick reference for regular expression syntax
.Any character except newlinea.c matches 'abc', 'a1c'\dDigit (0-9)\d+ matches '123' in 'abc123'\DNon-digit\D+ matches 'abc' in 'abc123'\wWord character (a-z, A-Z, 0-9, _)\w+ matches 'hello_1'\WNon-word character\W matches '@' in 'a@b'\sWhitespace (space, tab, newline)\s+ matches ' ' (spaces)\SNon-whitespace\S+ matches 'hello'[abc]Character set: a, b, or c[aeiou] matches vowels[^abc]Negated set: not a, b, or c[^0-9] matches non-digits[a-z]Range: a to z[A-Za-z] matches letters*0 or moreab*c matches 'ac', 'abc', 'abbc'+1 or moreab+c matches 'abc', 'abbc' (not 'ac')?0 or 1 (optional)colou?r matches 'color', 'colour'{n}Exactly n times\d{4} matches '2024'{n,}n or more times\d{2,} matches '12', '123'{n,m}Between n and m times\d{2,4} matches '12', '1234'*?0 or more (lazy)<.*?> matches '<b>' in '<b>text</b>'+?1 or more (lazy)\w+? matches 'a' in 'abc'^Start of string/line^Hello matches 'Hello world'$End of string/lineworld$ matches 'Hello world'\bWord boundary\bword\b matches 'word' exactly\BNon-word boundary\Bcat matches 'concatenate'(abc)Capturing group(\d+)-(\d+) captures two numbers(?:abc)Non-capturing group(?:http|https):// groups without capture(?<name>abc)Named capturing group(?<year>\d{4})-(?<month>\d{2})\1Backreference to group 1(\w+)\s\1 matches 'the the'(a|b)Alternation: a or b(cat|dog) matches 'cat' or 'dog'(?=abc)Positive lookahead\d(?=px) matches '5' in '5px'(?!abc)Negative lookahead\d(?!px) matches '3' in '3em'(?<=abc)Positive lookbehind(?<=\$)\d+ matches '100' in '$100'(?<!abc)Negative lookbehind(?<!\$)\d+ matches '100' in 'EUR100'gGlobal: find all matches/cat/g finds all 'cat' occurrencesiCase-insensitive/hello/i matches 'Hello', 'HELLO'mMultiline: ^ and $ match line boundaries/^start/m matches each line startsDotall: . matches newline too/a.b/s matches 'a\nb'uUnicode support/\p{L}/u matches Unicode lettersdIndices: provide match indices/cat/d returns start/end positions\d+\.\d+Decimal numberMatches '3.14', '0.5'[\w.]+@[\w.]+Simple email (basic)Matches 'user@example.com'https?://\S+URL (basic)Matches 'https://example.com/path'#[0-9a-fA-F]{6}Hex color codeMatches '#ff5733'\b\d{1,3}(\.\d{1,3}){3}\bIPv4 addressMatches '192.168.1.1'^\s+|\s+$Leading/trailing whitespaceUsed for trimming strings