Given:
var countries = ["Afghanistan", "United Kingdom", "Albania", "United Arab Emirates"];
var regex = new RegExp(countries.join("|"), "i");
$wikiDOM.find(".infobox td div li a").each(function(){
var newtext = $(this).text();
//console.log(newtext);
console.log(newtext.match(regex));
});
if I do:
console.log(newtext);
I get:
White
Asian
Black
Mixed
Arab
1]
United Kingdom
England and Wales
^
Legislative Grand Committee
So we do have a match for United Kingdom
yet when I run console.log(newtext.match(regex));
the console gives me null null null...
I am looking for a match of a string against the strings in the array and if there is a match, output that match in the console. In this case it'd be United Kingdom
Here it is a jsFiddle