Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove last slash from URL with regex

Tags:

regex

I have the following regex to remove last slash from a URL:

(.*)\/

i.e.: http://www.domain.com/clients/

If applied the regex to the example, it does the work fine, but the problem is when the URL does not have the last slash (it occur from time to time). It removes /clients.

How can I avoid this situation?

like image 830
Apalabrados Avatar asked Dec 05 '22 03:12

Apalabrados


1 Answers

Regex to remove only last slash in the URL

\/$

explanation:

\/ matches the character / literally
$ assert position at end of a line

DEMO

like image 137
MaxZoom Avatar answered Jan 14 '23 15:01

MaxZoom