Skip to content
_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN DE
Let's talk

Regex: Cheat Sheet with Practical Examples

11. 10. 2024 Updated: 27. 03. 2026 1 min read intermediate

Regular expressions are a powerful tool — if you know how. Practical cheat sheet to bookmark.

Basic Characters

. \d \D \w \W \s \S \b

Quantifiers

* + ? {3} {2,5} {3,} *?

Groups

(abc) (?:abc) a|b \1

Lookahead/behind

(?=x) (?!x) (?<=x) (?<!x)

Examples

Email: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}
IP: \b(?:\d{1,3}.){3}\d{1,3}\b
Date: \d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])
Phone CZ: (?:+420)?\s?\d{3}\s?\d{3}\s?\d{3}

In Practice

grep -oP ‘\b\d{1,3}(.\d{1,3}){3}\b’ access.log
import re; emails = re.findall(r’[\w.+-]+@[\w-]+.[\w.]+’, text)

Advanced Techniques

Named groups ((?P<name>...) in Python) improve regex readability and allow access to captured groups by name. Non-capturing groups ((?:...)) group without capturing, which speeds up the engine. Lookahead ((?=...)) and lookbehind ((?<=...)) check context without including it in the result — useful for password validation (must contain a digit, but you do not want the digit in the match).

Atomic groups and possessive quantifiers prevent backtracking and protect against ReDoS (Regular Expression Denial of Service). Always test regex on edge cases and large inputs. Lazy quantifiers (*?, +?) match the minimum number of characters, unlike greedy variants that match the maximum. For complex parsing (HTML, JSON, programming languages), do not use regex — use a dedicated parser.

Tip

Test on regex101.com. And if regex exceeds 2 lines, consider a parser.

regexprogrammingreference
Share:

CORE SYSTEMS team

We build core systems and AI agents that keep operations running. 15 years of experience with enterprise IT.