常见 Regex Patterns Reference
Reference 为通常 used regex patterns: whitespace, numbers, identifiers, 和文本 extraction.
Whitespace and Text Patterns
Match whitespace with \s (spaces, tabs, newlines) or [ \t\r\n] for specific types. Match words with \b\w+\b (word boundary + word chars). Match non-empty lines with ^.+$ (multiline flag). Strip HTML tags with <[^>]+> (naive, does not handle nested tags). Match quoted strings with "([^"\\]|\\.)*" (handles escaped quotes). Match trailing whitespace with \s+$ for cleanup. These patterns are building blocks for text processing.
- whitespace
- \s or [ \t\r\n]
- words
- \b\w+\b
- quoted
- "([^"\\]|\\.)*"
various types word boundary escaped quotes Number and Identifier Patterns
Match integers with -?\d+ (optional sign + digits). Match decimals with -?\d+\.\d+ (or -?\d*\.?\d+ for flexible). Match hex with 0x[0-9a-fA-F]+. Match identifiers with [a-zA-Z_][a-zA-Z0-9_]* (C-style) or [a-zA-Z_$][a-zA-Z0-9_$]* (JS-style). Match camelCase with [a-z][a-zA-Z0-9]*. Match snake_case with [a-z][a-z0-9_]*. Match kebab-case with [a-z][a-z0-9-]*. These patterns validate and extract common token types.
- integer
- -?\d+
- hex
- 0x[0-9a-fA-F]+
- identifier
- [a-zA-Z_][a-zA-Z0-9_]*
optional sign hex prefix C-style