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
- Qwen2.5-Coder-32B is an LLM that can code well that runs on my Mac - 12th November 2024
- Visualizing local election results with Datasette, Observable and MapLibre GL - 9th November 2024
- Project: VERDAD - tracking misinformation in radio broadcasts using Gemini 1.5 - 7th November 2024