this post was submitted on 23 Jul 2025
231 points (100.0% liked)
Programmer Humor
25253 readers
1161 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Here is my cheatsheet that has been very helpful. Obviously, this will not teach you how RegEx works, but is a good quick reference when I forget the exact syntax for something.
RegExp
Character classes
.
\w
\d
\s
\W
\D
\S
[abc]
[a-e]
a
ande
[1-9]
1
and9
[[:print:]]
[^abc]
a
,b
orc
Anchors
\G
^
$
\A
\Z
\z
\b
\B
^abc
abc
abc$
abc
For multiline patterns (
m
flag),^
and$
will act as start and end of line.Escaped characters
\. \* \\
\t
\n
\r
Groups
(abc)
(a|b)
a
orb
(?:abc)
abc
, but don't capture\1
Quantifiers
a*
a+
a?
a{5}
a{,3}
a{3,}
a{1,3}
Lookahead & Lookbehind
| Pattern | Description | |
|
a(?=b)
| Matcha
inbaby
but not inbay
| |a(?!b)
| Matcha
inStan
but not inStab
| |(?<=a)b
| Matchb
incrabs
but not incribs
| |(?<!a)b
| Matchb
infib
but not infab
| |(?<![a-z])abc(?![a-z])
| Matchabc
without any letters before/after |Raw Markdown