On 02/19/21 10:26, Tom Lane wrote: >> "foo\nbar".match(/([\w\W]+)/)[1]; >> "foo >> bar" > > Oooh, that's very interesting. I guess the advantage of that over using > the 's' flag is that you can have different behaviors at different places > in the same regex.
Perl, Python, and Java (at least) all have a common syntax for changing flags locally in a non-capturing group, so you could just match (?s:.) -- which I guess isn't any shorter than [\w\W] but makes the intent more clear. I see that JavaScript, for some reason, does not advertise that. We don't either; we have (?:groups) without flags, and we have (?flags) but only global at the start of the regex. Would it be worthwhile to jump on the bandwagon and support local flags in groups? We currently give 2201B: invalid regular expression: invalid embedded option on an attempt to use the syntax, so implementing it couldn't break anything someone is already doing. Regards, -Chap