Aller au contenu
uencoder

Commun Regex Motifs Référence

Référence pour commonly utilisé regex motifs: whitespace, nombres, identifiers, et texte 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]
various types
words
\b\w+\b
word boundary
quoted
"([^"\\]|\\.)*"
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+
optional sign
hex
0x[0-9a-fA-F]+
hex prefix
identifier
[a-zA-Z_][a-zA-Z0-9_]*
C-style

Outils associés

参考链接