Sindar
Sindar

Reputation: 10839

Use \ and / on a .match()

Well i have a little problem but really strange.

So basically i analyzed URL represented by a string. The only thing i want to check is if this URL contains 'chrome-extension://'

So basically i've tried to escape these caracter like that but it still didn't work...

if(!URL.match(/(chrome\-extension\:\/\/)/i))

Upvotes: 1

Views: 266

Answers (3)

Jarrett Meyer
Jarrett Meyer

Reputation: 19573

This'll work...

var url = "chrome-extension://etc";
alert("match: " + url.match(/^chrome-extension:\/\//));

Check out jsfiddle.

Upvotes: 0

jensgram
jensgram

Reputation: 31508

Alternatively:

if (URL.indexOf('chrome-extension://') < 0) {
    // No match
}

Upvotes: 4

vladh
vladh

Reputation: 49

String functions will be much faster than regex with such small things:

if(URL.substr(0,19) != "chrome-extension://")

Upvotes: 2

Related Questions