Zum Inhalt springen
_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
Referenzen Technologien Blog Know-how Tools
Über uns Zusammenarbeit Karriere
CS EN DE
Lassen Sie uns sprechen

Regex: cheat sheet s praktickými příklady

11. 10. 2024 1 Min. Lesezeit intermediate

Regulární výrazy jsou mocný nástroj — pokud víte jak. Praktický cheat sheet k bookmarknutí.

Základní znaky

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

Kvantifikátory

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

Skupiny

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

Lookahead/behind

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

Příklady

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

V praxi

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

Tip

Testujte na regex101.com. A pokud regex přesáhne 2 řádky, zvažte parser.

regexprogramováníreference
Teilen:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.