jQuery 1.9.1 | If variable matches comma-delimited string, do something, else, do some other thing...

jQuery 1.9.1 | If variable matches comma-delimited string, do something, else, do some other thing...

But not so easy as I thought in my scenario, I have a variable which is basically the video ID of a Youtube link that I extract from a url once clicked, which, if matching a substring (video ID) of a comma-delimited string of video IDs found in a input text box, should trigger an event., like so:

  1. var videoID =$("#videoIDholder").val(); // <-- the stored link video ID
  2. var str = $("input[name=StringOfVideoIDs]").val().split(',');
  3. if ($.inArray(videoID, str) !== -1) {
  4. alert('match!');
  5. } else {
  6. alert('no match!');
  7. };

Problem is, with the above code, the console (Firebug) reflects what's in videoID or str but alerts don't show if there's a genuine match or not, i.e., the above code triggers the match alert when the text box contains any video ID, and when the text box is empty the "no match!" alert gets triggered. I don't have to know the location of the matching comma-delimited ID located in the text box, just if there's a comma-delimited ID that is a duplicate (or not a duplicate) of the ID extracted from the video link. I don't mind using indexOf.

The closest I got was with this which works with one hard-coded ID:

  1. var str = $("input[name=StringOfVideoIDs]").val();
  2. var n=str.match(/GHFDr254gs7/g);
  3. alert(n);

However, the above video ID in bold must be replaced by a variable, like this:

  1. var videoID =$("#videoIDholder").val();
  2. var str = $("input[name=StringOfVideoIDs]").val();
  3. var n=str.match(/videoID/g);  // <--- Is this possible?
  4. alert(n);

I read that in this scenario, you would have to use .match(new RegExp( ... , but this is new for me.

Matching a variable in a dynamic environment is what I need, any hints??