P.Brian.Mackey P.Brian.Mackey - 1 year ago 211
Javascript Question

Regex to remove last / if it exists as the last character in the string

I would like a regular expression or otherwise some method to remove the last character in a string if and only if that character is '/'. How can I do it?

Answer Source
string = string.replace(/\/$/, "");

$ marks the end of a string. \/ is a RegExp-escaped /. Combining both = Replace the / at the end of a line.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download