home blog portfolio Ian Fisher

Regular expressions cheatsheet

\s   whitespace
\S   non-whitespace

Python

(?:...)         non-capturing group
(?P<name>...)   named group
(?#...)         comment
(?!...)         negative lookahead assertion

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