Although the title may not be entirely appropriate, my goal is to create a regex that will remove any trailing '/' at the end of a URL under certain conditions.
For example:
http://stackoverflow.com/questions/ask/
to
http://stackoverflow.com/questions/ask
I initially achieved this using ^(.*)\/
(see example), but now I require a modification and I'm uncertain about how it should be done.
The change I need is to NOT remove the '/' if it is on the main page:
http://stackoverflow.com/ stays http://stackoverflow.com/
http://stackoverflow.com/questions/ changes to ttp://stackoverflow.com/questions
In my understanding, the condition should involve checking if the URL ends with text between two '/' characters and does not contain any '.' character. However, I am struggling to implement this condition successfully.
What approach should be taken?
EDIT
Sometimes the URLs may not include 'http' or 'https', so it would be acceptable if the regex worked on ordinary text as well.