Я не знаю, почему существуют различия между re
и /^Text(\d+)?[.]json$/g
.
Я использовал неправильное выражение?
$ node -v
v6.15.0
$ node
> list =[ 'Text.json',
'Text1.json',
'Text2.json',
'Text3.json',
'Text4.json' ]
> re = new RegExp(/^Text(\d+)?[.]json$/g)
> list.filter(f => re.test(f))
[ 'Text.json', 'Text2.json', 'Text4.json' ]
> list.filter(f => /^Text(\d+)?[.]json$/g.test(f))
[ 'Text.json',
'Text1.json',
'Text2.json',
'Text3.json',
'Text4.json' ]
> String(/^Text(\d+)?[.]json$/g) === String(re)
true