regex url match

by Oliver Kelso

HTML

<a data-sc="download_something" href="http://test.com/test/1" title="test link 1">test link 1</a>
<a data-sc="download_something" href="http://test.com/test/2" title="test link 1">test link 2</a>
<a data-sc="download_something" href="http://www.pixelsoul.com/test/3" title="test link 1">test link 3</a>
<a data-sc="download_something" href="http://test.com/test/4" title="test link 1">test link 4</a>
<a data-sc="download_something" href="http://google.com/test/5" title="test link 1">test link 5</a>
<div id="urls"></div>

JavaScript

function matchInArray(string, expressions) {
    for (var i = 0; i < expressions.length; i++) {
        if (string.match(expressions[i])) {
            return true;
        }
    }
    return false;
};

var urls = [
'/.*\.pixelsoul\.com.*/',
'/.*\.test\.com.*/'
];
var found = "";
$('a[data-sc^="download_"]').each(function(e){
  
  var href = $(this).attr('href');
  var title = $(this).attr('title');
  
  if(matchInArray(href, urls)){            
    console.log(href + " - " + title);
    found += href + " - " + title + "<br />";
    $('#urls').html(found);
  }
});