Есть 2 способа записи регулярных выражений

var reg = /ab+c/i
var reg = new RegExp("ab+c", "i")

Сопоставить строку с регулярным выражением

if(/\s/.test("строка")){
    // В строке есть пробелы!
}

Заменить все вхождения подстроки в строке, без учёта регистра

var str="Welcome to Microsoft! ";
str = str + "We are proud to announce that Microsoft has ";
str = str + "one of the largest Web Developers sites in the world.";

document.write(str.replace(/microsoft/gi, "W3Schools"));
Welcome to W3Schools! We are proud to announce that W3Schools
has one of the largest Web Developers sites in the world.
-----------
-----------