I'm seeing some very strange behaviour with a little script I'm writing (and running with Node v6). If I place the following line in a script, say index.js
:
console.log((/autonom.*/ig).test('autonomy'))
and run it with node index.js
, I'm seeing false
. Unexpected!
Stranger still is that if I open an interactive shell with node
, and run:
> (/autonom.*/ig).test('autonomy')
true
I get true
, as expected. Is there any reason why the code in the script would have a different effect to that in the repl?
Edit the regex had a little bit of spice for no real reason. I see the same behaviour even with the trivial:
console.log((/^autonomy$/).test('autonomy'))
Edit the plot thickens hugely:
console.log((/autonom\S*/i).test('autonomy'))
console.log((/autonom\S*/i).test('autonomy'))
node index.js
with this file prints:
true
false