Encountered a strange behaviour with negated charatcer classes traversing newlines without m/multiline
provided.
> node
Welcome to Node.js v22.7.0.
Type ".help" for more information.
> 'abcnabcnabcn'.replace(/b[^z]+/g, '')
'a'
> 'abcnabcnabcn'.replace(/b[^zn]+/g, '')
'ananan'
I expected that the first result would only be the case when the m
multiline
flag is enabled:
> 'abcnabcnabcn'.replace(/b[^z]+/gm, '')
'a'
Is this a bug, or is this expected? If it is expected, what is the reasoning?