Answer the question
In order to leave comments, you need to log in
How to add a slash to the end of a line in a regular expression?
There is a regular expression that removes duplicate slashes from the path:
const url = 'http://localhost////example///author/admin';
clean_url = url.replace(/([^:]\/)\/+/g, "$1")
console.log(clean_url) // http://localhost/example/author/admin
Bad: http://localhost/example/author/admin
Good: http://localhost/example/author/admin/
Bad: http://localhost/example/author/admin?query=1212
Good: http://localhost/example/author/admin/?query=1212
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question