Check Array Entries with Regex

I have an Array with one or more entries. Each one is a string (List of urls in open Tabs via Firefox SDK). I want to check if a specific url is already opened in some of the tabs (nothing special till now).

My problem is, that the url in tab list can have four diffrent fourms. For example:

Url I want to find in the tablist:

But the url can also look like this:

Of course the last part of the url (after /test/...) is always something diffrent. If I wasn't able to find one of the four urls in the tablist i want to call some other action.

My Solution till now is to build some if-chain:

if (res !== url1) {
  if (res !== url2) {
    if ...

But i thought there must be some more elegant way. Maybe via RegEx? I already have a capture to catch the first part (which stays the same with it four forms. But i dont know how to implent this probably.


var urls = ["","",""]
var filtered = urls.filter(function(url) 
       return url.indexOf("cf#") > -1 && url.endsWith("/test/de.html")

var contains = filtered.length > 0

If you want to use regex you can do this by using groups for the middle part, which is explained in detail here:

Practically, your regex would look something like that:


Where ... must be replaced by the middle parts of the url which differ. Note that | is "or" used to provide multiple possibilities within the group. The character / and . must be escaped since they have special roles in regex.

I hope that helps!

My English is not good,Do not fully understand what you mean,According to my idea,You should need a regular expression,Only to match the first.If I am wrong, please @ me.

I hope that helps!

var reg = /^https:\/\/cmsr\-author\.de\/cf#\/(?:\w+\/)+test\/de\.html$/gi;
var str1 = "";
var str2 = "";
var str3 = "";
var str4 = "";

Need Your Help

How to scan QR Code in Windows Phone 8.1 using Phonegap/Cordova/WinJS/HTML/CSS/JS?

windows cordova windows-phone-8 windows-phone-8.1 zxing

I am using ZXing.Net library to scan/read QR codes from camera in Windows Phone 8.1. I went through this sample: But this is for Windows Phone 8.0

Javascript event when mouse leaves browser window

javascript ajax safari prototypejs mouseout

I'd like some Javascript code to run when the mouse leaves the browser window. I only need to support Safari (WebKit.)