JavaScript RegExp test()
RegExp 物件的 test() 方法用來測試字串中是否有符合正規表示式的字串,執行後會返回 boolean true 或 false。
語法:
regexObj.test(str);
用法:
const str = 'hello world!';
const result = /^hello/.test(str);
// true
result;
RegExp 物件的 test() 方法用來測試字串中是否有符合正規表示式的字串,執行後會返回 boolean true 或 false。
語法:
regexObj.test(str);
用法:
const str = 'hello world!';
const result = /^hello/.test(str);
// true
result;