JavaScript regular expressions

// Escape regexp special characters
function escape_regexp(text) {
    return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
}

console.log(escape_regexp("$0.5") === "\\$0\\.5")


// convert string to regexp
console.log(new RegExp("\\d+", "gi")) // /\d+/gi