Possible Duplicate:
Javascript Regexp dynamic generation?
I am trying to create a new RegExp with a variable; however, I do not know the sytax to do this. Any help would be great!
I need to change this: (v.name.search(new RegExp(/Josh Gonzalez/i)) != -1) change it to this: (v.name.search(new RegExp(/q/i)) != -1). I basically need to replace the "josh" with the variable q ~ var q = $( 'input[name="q"]' ).val();
Thanks for the help
$( 'form#search-connections' )
.submit( function( event )
{
event.preventDefault();
var q = $( 'input[name="q"]' ).val();
console.log( _json );
$.each( _json, function(i, v) {
//NEED TO INSERT Q FOR JOSH
if (v.name.search(new RegExp(/Josh Gonzalez/i)) != -1) {
alert(v.name);
return;
}
});
}
);