Skip to content Skip to sidebar Skip to footer

Javascript Regex Url Matching

I have this so far: chrome.tabs.getSelected(null, function(tab) { var title = tab.title; var btn = ' ' +

Solution 1:

Solution 2:

Solution 3:

You are creating the RegExp object, but you're not matching it against anything. See here for how to use it (by the way, the syntax is also wrong, it's either /expression/modifiers or RegExp(expression, modifiers)).

Solution 4:

match() should take a RegExp object as argument, not a string. You could probably just remove the single quotes '' from around the expression to make it work. For future reference, you should also escape the periods . in the expression (as it is they will match any single character), and insert a ^ in the beginning to only allow this match in the beginning of the URL.

Post a Comment for "Javascript Regex Url Matching"