#Chrome, FF, and Node agree on a regexp result I can't understand

11 messages · Page 1 of 1 (latest)

neon lake
#

With those two JS engines in agreement, it's hard to imagine I'm right, but

'\nabcd'.match(/.{1,4}/g)

['abcd']

How is this not ['\nabc', 'd']? Why is the \n being stripped?

#
> '\nabcd'.match(/.{1,2}/g)
[ 'ab', 'cd' ]

> '\rabcd'.match(/.{1,2}/g)
[ 'ab', 'cd' ]

> '\tabcd'.match(/.{1,2}/g)
[ '\ta', 'bc', 'd' ]

newline and return are stripped, but tab isn't?

prime crag
neon lake
#

well. that's horrifying

#

thank you

coral crypt
#

if you want an "any character" token without dotall, use [^]

#

it's an exclusive set that doesn't exclude anything

versed arch
neon lake
#

i guess it makes sense. however it also shows how weak a lot of my test cases have been

prime crag
#

It isn't just JS either - Grep/ripgrep/VSCode search (which is just ripgrep under the hood) do a similar thing