I would like to know how to match a string against an array of regular expressions.
I know how to do this looping through the array.
I also know how to do this by ma
How about creating a regular expression on the fly when you need it (assuming the array changes over time)
if( (new RegExp( '\\b' + array.join('\\b|\\b') + '\\b') ).test(string) ) {
alert('match');
}
demo http://jsfiddle.net/gaby/eM6jU/
For browsers that support javascript version 1.6 you can use the some() method
if ( array.some(function(item){return (new RegExp('\\b'+item+'\\b')).test(string);}) ) {
alert('match');
}
http://jsfiddle.net/gaby/eM6jU/1/