// 定義一個比對的規則,以下的 \s{1} 表示僅能有1個空格。
var pattern = /the\s{1}book/;
// 或以下這個寫法:
//var pattern = new RegExp(/the\s{1}book/);
// 以下是想要比對的字串
var str = "the book";
//var str = "The book";
alert(pattern.test(str));
var pattern = /the\s{1}book/;
var pattern = /the\s{1}book/i; // i 是 ignore(忽略) 的意思。
// 或
// var pattern = new RegExp(/the\s{1}book/, "i");
var str = "visit abc and def and abc";
var new_str = str.replace(/ABC/, "101"); // 找不到
console.log(new_str); // visit abc and def and abc
var str = "visit abc and def and abc";
var new_str = str.replace(/ABC/i, "101");
console.log(new_str); // visit 101 and def and abc
var str = "visit abc and def and abc";
var new_str = str.replace(/ABC/ig, "101");
console.log(new_str); // visit 101 and def and 101
var pattern;
var str = "";
console.log(pattern.test(str));