I'm having an issue, where I need to add leading and trailing slashes to string if it's not having them, or do nothing if string is already has it.
For example:
"/path" => "/path/"
"path/" => "/path/"
"path" => "/path/"
"/path/" => "/path/"
"/" => "/"
"" => "/"
I've tried to use this regular expression, but it's not adding trailing slash:
'/path'.replace(/(^\/?)|(\/?$)/, '/'); // output is "/path"