javascript - RegExp is not working properly -


i'm writing function switches urls embed url. so, have two-dimensional array has original url , embed url.

i'm trying use regexp make sure valid url, won't work..

this code worked:

arr[x].match(/^(http:\/\/){0,1}(www.){0,1}(allmyvideos.net\/){1}([a-z0-9])+$/ig); 

while code won't work:

var sites = [     ["allmyvideos.net/vidid", "allmyvideos.net/embed-vidid"] ]; var arr = document.getelementbyid('original').value.split("\n"); for(var x in arr) {     var regex = new regexp("/^(http:\/\/){0,1}(www.){0,1}(" + sites[0][0].replace("vidid", "").replace(/[\/]/g, "\\/") + "){1}([a-z0-9])+$/ig");     regex.test(arr[x]); } 

what doing wrong here second approach not working?

the new regexp() constructor form doesn't use surrounding / characters:

var re = new regexp("thing check", "ig"); re.test("thing check") // => true 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -