But I found Firefox was choking on some regular expressions I put into the backend tooling for my website.
That s flag, letting an expression like /(.*)/s match multiple lines (because it says to treat linebreaks as normal whitespace-ish stuff) was a critical tool going back to my Perl days...
So to quote T.J. Crowser in StackOverflow:
You are looking for theHis examples then show `[\s\S]` replacing good old `.`. I'm happy to have the workaround, but man is that an ugly one!/.../s
modifier, also known as the dotall modifier. It forces the dot.
to also match newlines, which it does not do by default.
The bad news is that itdoes not exist in JavaScript(it does as of ES2018, see below). The good news is that you can work around it by using a character class (e.g.\s
) and its negation (\S
) together, like this:
[\s\S]
I wish I knew more about the history here - feels like Firefox was sticking to the spec more righteously than Chrome, which I guess is fair enough, but why was such a critical piece missing from JS/ECMAScript in the first place? It smells a little bit like some religious war fallout, some coders didn't like multiline conceptually, or something...
No comments:
Post a Comment