JavaScript matches current url versus wildcard string?
I'm trying to match the following line:
http://*/*/checkout
to this url:
http://www.url.com/sub-folder/checkout
Ultimately what I am trying to do is find a way to render my JavaScript widget on specific pages, allowing conditions like above to be added.
How can I use a string to find out if the current url is the same?
+3
Laine
source
to share
1 answer
Use a regular expression:
> /^http:\/\/.*?\/.*?\/checkout$/.test('http://www.url.com/sub-folder/checkout')
true
Here's a more readable version:
RegExp('^http://.*?/.*?/checkout$').test('http://www.url.com/sub-folder/checkout')
+4
Blender
source
to share