If the '[' special character is used in a regex constructor object, it throws Invalid regular expression: /mat[/: Unterminated character class
function findMatch() {
var string="Find the match";
var text = "Mat[";
string.replace(new RegExp(text, 'gi'), "found")
}
Why is this error occurring and how can I solve this?