I have an input array which contains various domains:
var sites = ["site2.com", "site2.com", "site3.com"];
I need to check, whether certain string domainName matches one of these sites. I used
indexOf which worked fine, however problem occured when certain domainName was shown with subpage, e.g.
subpage.site1.com.
I tried to use some method with RegExp testing instead:
if(sites.some(function(rx) { return rx.test(domainName); })
however the first problem was that I needed to change "" for every element to "\\" to make it work with RegExp:
var sites = [/site1.com/, /site2.com/, /site3.com/];
while I want to keep array with quotation marks for end-user.
Second problem was that it returns true for in cases where compared domainName is not in array, but partially its name contains is part of element in array, for example anothersite1.com with site1.com. It's rare case but happens.
I can modify my input array with RegExp will start and end with ^$ escape characters, but it will complicate it even more, especially that I will need to also add ([a-z0-9]+[.]) to match subpages.
I tried to use replace to change "foo" to \foo\, but I was unable since quation marks defines array elements. Also I tried to use replace with concat to merge string with escape characters to achieve element looking like RegExp formula from site1.com to ^([a-z0-9]+[.])*site1\.com$ but got issues with escaping characters.
Is there a simpler way to achieve this goal?
\bsite1\.com$