I have a variable patt with a dynamic numerical value
var patt = "%"+number+":";
What is the regex syntax for using it in the test() method?
I have been using this format
var patt=/testing/g;
var found = patt.test(textinput);
TIA
I have a variable patt with a dynamic numerical value
What is the regex syntax for using it in the test() method? I have been using this format
TIA
| |||
feedback
|
Yeah, you pretty much had it. You just needed to pass your regex string into the RegExp constructor. You can then call it's
Hope that helps :) | |||
feedback
|
You have to build the regex using a regex object, rather than the regex literal. From your question, I'm not exactly sure what your matching criteria is, but if you want to match the number along with the '%' and ':' markers, you'd do something like the following:
You can read up more here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp | ||||
feedback
|
You're on the right track
Example: http://jsfiddle.net/jasongennaro/ygfQ8/2/ You should not use And your pattern is fine without turning it into a regex literal. | |||||||||||
feedback
|