Reputation: 13497
I want the following regular expression:
/(ending)$/
Where ending is a variable. I discovered that to use variables with regular expressions I must use regular expression constructors. So I tried:
var pattern = new RegExp((ending)$);
But this does not work either! This works if I do not include the grouping parenthesis and dollar sign, but I need those special characters as part of my pattern!
I tried to wrap the special characters in quotations, and also cancel them out by using a backslash, but nothing seems to work! What should I do to include special characters in my regular expression constructor?!
Upvotes: 0
Views: 61
Reputation: 44298
it takes a string...
var pattern = new RegExp("(" + ending+ ")$");
Upvotes: 4