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
- Qwen 3.8 27B is excellent, but it defaults to wildly overthinking things - 16th August 2026
- Now we have a timeline of the OpenAI accidental attack against Hugging Face - 7th August 2026
- One-shotting a Raccoon Heist game using Claude Fable 5 - 5th August 2026