Matching newlines in JavaScript
20th September 2004
Just a quick note: the . character in a JavaScript regular expression will never match a newline character. If you want to match any character including newlines you can use the [\s\S] character class instead, which means “any character that’s either whitespace or not whitespace”.
This differs from both Python and Perl, where regular expression flags can be used to alter the behaviour of the . character (re.DOTALL and /s respectively).
This tip courtesy of the denizens of #javascript on Freenode.
More recent articles
- What happens if AI labs train for pelicans riding bicycles? - 13th November 2025
- Reverse engineering Codex CLI to get GPT-5-Codex-Mini to draw me a pelican - 9th November 2025
- Video + notes on upgrading a Datasette plugin for the latest 1.0 alpha, with help from uv and OpenAI Codex CLI - 6th November 2025