SOURCE

var text = "cat, sat, bat, fat";
var pattern = /.at/g;

// match()
var matches = text.match(pattern);
console.log(matches);

// search()
var pos = text.search(/at/);
console.log(pos);

// replace()
var result = text.replace("at", "ond");
console.log(result);

result = text.replace(/at/g, "ond");
console.log(result);

result = text.replace(/(.at)/g, "word ($1)");
console.log(result);

function htmlEscape(text) {
    return text.replace(/[<>"&]/g, function(match){
        switch(match) {
            case "<":
                return "&lt;";
            case ">":
                return "&gt;";
            case "&":
                return "&amp;";
            case "\"":
                return "&quot;";
        }
    });
}

var htmlElem = "<p class=\"greeting\">Hello World</p>";
// alert(htmlEscape(htmlElem));

// split()
var colorText = "red,blue,green,yellow";
var colors1 = colorText.split(",");
var colors2 = colorText.split(",", 2);
var colors3 = colorText.split(/[^\,]/);
console.log(colors1, colors2, colors3);
console 命令行工具 X clear

                    
>
console