Post

regex

πŸ” Regex Shortcuts

Shortcut Action
* Match preceding character 0 or more times
+ Match preceding character 1 or more times
. Match any single character
x|y Match either β€˜x’ or β€˜y’
\ Escape a special character
b The character b
abc The string abc

🧩 Regex Character Class Shortcuts

Shortcut Action
\d Match a digit character
\D Match a non-digit character
\s Match a single white space character (space, tab, form feed, or line feed)
\S Match a single character other than white space
\w Match any alphanumeric character (including underscore)
\W Match any non-word character

πŸ”  Regex Character Set Shortcuts

Shortcut Action
[abc] Match any one of the characters in the set β€˜abc’
[^abc] Match anything not in character set β€˜abc’
[\b] Match a backspace

πŸ” Advanced Regex Shortcuts

Shortcut Action
^ Match beginning of input
$ Match end of input
\b Match a word boundary
\B Match a non-word boundary
?= Lookahead
?! Negative lookahead

πŸ”„ Conditional Regex Shortcuts

Shortcut Action
?<= Lookbehind
?<! Negative lookbehind
?> Once-only subexpression
?() If-then condition
?()| If-then-else condition
?# Comment

πŸ”’ Regex Quantifier Shortcuts

Shortcut Action
{n} Match exactly n occurrences of preceding character
{n,m} Match at least n and at most m occurrences of the preceding character
? Match 0 or 1 occurrence of preceding character

🧩 Regex Escape Sequences

Shortcut Action
\cX Match control character X in a string
\n Match a line feed
\r Match a carriage return
\t Match a tab
\0 Match a NULL

🧩 Advanced Regex Escape Sequences

Shortcut Action
\f Match a form feed
\v Match a vertical tab
\xhh Match character with code hh (2 hex digits)
\uhhhh Match character with code hhhh (4 hex digits)

πŸ” Search Option Shortcuts

Shortcut Action
g Global search
i Case-insensitive search
m Multi-line search
y β€œSticky” search match starting at current position in target string

πŸ§‘β€πŸ€β€πŸ§‘ Grouping & Back-Reference Shortcuts

Shortcut Action
(x) Match β€˜x’ and remember the match
(?:x) Match β€˜x’ but do not remember the match
\n A back reference to the last substring matching the n parenthetical in the regex
This post is licensed under CC BY 4.0 by the author.