Regex for determining if URL has slash at the end

If I pull in window.location
var curURL = window.location;
currURL = currURL.split("?")[0].split("#")[0];

Open in new window

How can I detect if currURL has a trailing slash (due to a query string that may have been present)?

Examples: returns returns

But I want a regex to test if trailing slash is there or not... or best solution to remove that trailing slash
Who is Participating?
Robert SchuttSoftware EngineerCommented:
If you just want to get rid of it you can use:
currURL = currURL.split("?")[0].split("#")[0].replace(/\/$/,'');

Open in new window

If you wanna do through regex here is the code

var curURL = " ";
var reg = new RegExp(".com/[?]*[a-zA-Z0-9=&]*");
curURL = curURL.replace(reg, ".com");
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.