I am developing a Chrome extension that enables users to customize content on specific websites. I want to allow users to specify these websites using wildcards, like http://*.google.com
or http://google.com/*
While researching, I came across the following code snippet:
currentUrl = "http://google.com/";
matchUrl = "http://*.google.com/*";
match = RegExp(matchUrl.replace(/\*/g, "[^]*")).test(currentUrl);
However, there are some issues with this implementation.
http://test.google.com/
is considered a match
http://google.com/
is not recognized as a match
http://test.google.com
is also not identified as a match
http://.google.com/
is matched
Clarification:
http://google.com
should be a match, but it isn't in this code execution.
How can I write a JavaScript function that accurately checks for matches?