数値の存在をテストするために (JavaScript で) RegExp オブジェクトを作成します。
var test = new RegExp( '[0-9]', 'g' );
こんな感じで使ってます
console.log( test.test( '0' ) ); // true
console.log( test.test( '1' ) ); // false - why?
これの出力はさらに紛らわしいです:
console.log( test.test( '1' ) ); // true
console.log( test.test( '0' ) ); // false - why?
console.log( test.test( '1' ) ); // true
console.log( test.test( '2' ) ); // false - why?
console.log( test.test( '2' ) ); // true - correct, but why is this one true?
g
修飾子を削除すると、期待どおりに動作します。
私が信じているように、これはバグですか、それとも仕様の特定の部分ですか? g
修飾子はこのように使用することになっていますか? (複数のタスクに同じ式を再利用しているため、修飾子がまったくありません)