Javascript String matchString(patternString, flags)

Description

Javascript String matchString(patternString, flags)

// escapes patternString to valid regex pattern, converts to regex object, then matches string
String.prototype.matchString = function (patternString, flags) {
    return RegExp(escapeRegex(name), flags).exec(this)

    function escapeRegex(str) {
        return str.toString().replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
    }/*w w w .ja v a2 s . c o m*/
}



PreviousNext

Related