MJ
asked on
Regex for determining if URL has slash at the end
If I pull in window.location
Examples:
http://www.mydomain.com returns http://www.mydomain.com
http://www.mydomain.com/?a=b returns http://www.mydomain.com/
But I want a regex to test if trailing slash is there or not... or best solution to remove that trailing slash
var curURL = window.location;
currURL = currURL.split("?")[0].split("#")[0];
How can I detect if currURL has a trailing slash (due to a query string that may have been present)?Examples:
http://www.mydomain.com returns http://www.mydomain.com
http://www.mydomain.com/?a=b returns http://www.mydomain.com/
But I want a regex to test if trailing slash is there or not... or best solution to remove that trailing slash
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
var curURL = "http://www.mydomain.com/?a=b ";
var reg = new RegExp(".com/[?]*[a-zA-Z0-
curURL = curURL.replace(reg, ".com");