regex
15 pages
-
regex alternation — | operator and grouping
Use | in regex to match one of several alternatives. Covers grouping with (), non-capturing groups (?:...), and alternation precedence.
-
regex anchors — ^ and $ match start and end
Use ^ to match the start and $ to match the end of a string or line in regex. Covers \A, \Z in Python and the multiline flag.
-
regex character classes — [...], \d, \w, \s
Use regex character classes to match sets of characters. Covers [...], negated [^...], shorthand classes \d \w \s and their inverses.
-
regex match date — YYYY-MM-DD and common formats
Regex patterns to match ISO 8601 dates (YYYY-MM-DD) and other common date formats. Covers validation and extraction in JavaScript and Python.
-
regex email pattern — validate and extract email addresses
Regex pattern to validate or extract email addresses. Covers basic validation, RFC 5322, and practical patterns for JavaScript and Python.
-
regex global replace — replace all matches in JavaScript, Python, sed
Replace all regex matches in a string using the global flag in JavaScript, re.sub() in Python, or sed s///g. Covers case-insensitive and multiline replacements.
-
regex match IPv4 address
Regex pattern to match and validate IPv4 addresses (0-255 per octet). Covers simple and strict patterns in JavaScript and Python.
-
regex lookahead and lookbehind — (?=...) (?<=...) (?!...) (?<!...)
Use regex lookahead (?=...) and lookbehind (?<=...) assertions to match patterns without including them in the result.
-
regex multiline flag — ^ and $ match line start/end
Use the multiline flag (m) so ^ and $ match the start and end of each line, not just the entire string. Covers JavaScript, Python, and the DOTALL flag.
-
regex named capture groups — (?P<name>) and (?<name>)
Use named capture groups in regex to extract named parts of a match. Covers Python (?P<name>), JavaScript (?<name>), and backreferences.
-
regex non-greedy matching — .*? vs .*
Use non-greedy (lazy) quantifiers like .*? to match as little as possible. Explains the difference between greedy and lazy matching with examples.
-
regex match phone number — international and US formats
Regex patterns to match phone numbers in US, international (+1-XXX), and flexible formats. Covers extraction and normalization.
-
regex replace with capture group backreference
Use capture group backreferences ($1, \1, \g<1>) in regex replacements to reuse matched text. Covers JavaScript, Python, sed, and named groups.
-
regex match URL — http, https, and optional path
Regex patterns to match and extract URLs (http/https) from text in JavaScript and Python. Covers optional paths, query strings, and fragments.
-
regex word boundary \b — match whole words only
Use \b word boundary assertion to match whole words and avoid partial matches. Covers \b, \B, and word boundary in different languages.