Regular expressions
Utilities offered by many programming languages for parsing text and extracting information based on a pattern. Based on concepts from theoretical computer science. Best suited for unstructured text; not to be used to parse HTML.
Cheatsheet
\s whitespace
\S non-whitespace
Python
(?:...) non-capturing group
(?P<name>...) named group
(?#...) comment
(?!...) negative lookahead assertion
\n
matches a literal newline.re.DOTALL
causes.
to also match newlines.re.MULTILINE
doesn't affect newline matching; it causes^
and$
to match line boundaries as well.
JavaScript
const pat = /([0-9]{4})-([0-9]{2})-([0-9]{2})/g;
pat.test("on 2025-05-04") // true
pat.exec("on 2025-05-04") // ["2025-05-04", "2025", "05", "04"]
pat.exec("abc") // null