I need to include a "variable" in my regex that will be different each time it is called.
Very fustrated, this would have taken 2 seconds in Perl.
Here is my code:
for (y=0; y < response.length -1; y++){
var _row = response[y].split(':');
var str = "_row[1]";
if(str.match("/^"+_inputText.value+"/i")){
_responseText += '<option value="'+_row[0]+'">'+_row[1]+', '+_row[2]+'</option>';
}
}
I CANNOT get the variable to expand into the regex.
I have tried: everything I can think of...
re.test("/^"+_inputText.value+"/i")
This seemed to parse the variable into the regex, but I could never get it to match, or test positive.
var _regex = "/^"+_inputText.value+"/i";
Now _regex IS the string "/^ea/i", when passing ea as the inputtext.
But then, I can't get this to create a match:
var _regex = "/^"+_inputText.value+"/i";
for (y=0; y < response.length -1; y++){
var _row = response[y].split(':');
var str = "_row[1]";
if(str.match(_regex)){
_responseText += '<option value="'+_row[0]+'">'+_row[1]+', '+_row[2]+'</option>';
}
}
???
Any help?
I just need a value supplied by the user to filter an array, weeding out those items that don't start with what the user typed.
Thanks!