var txtpattern = '/[a-z]+/';
var regex = new RegExp(txtpattern);
var result = txtstring.match(regex); //returns null
var result = txtstring.match(/[a-z]+/); //returns some value
My query is, Is there any way to set the dynamic pattern in match arguments?
When using
new Regex(), you need to remove the start and end/characters, like so: