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.