Regular expressions 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
See also: ref/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