RegExp.prototype.test()

(標準組み込みオブジェクト > RegExp > メソッド)
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test

正規表現オブジェクト.test(文字列)

RegExp オブジェクトの test メソッドは、対象となる文字列が正規表現とマッチするかどうかをテストし、結果として論理値を返す。引数に指定した文字列が少なくとも一つ正規表現とマッチした場合は true を返す。マッチしなかった場合は false を返す。

let regexp = /ball/;
let str1 = 'Go to see a baseball game';
let str2 = 'Make a cake tomorrow';

console.log(regexp.test(str1));
>> true
console.log(regexp.test(str2));
>> false
inserted by FC2 system