I want to extract the string from the input string with “/” removed from the beginning and the end (if present).
For example :
Input String : /abcd
Output String : abcd
Input String : /abcd/
Output String : abcd
Input String : abcd/
Output String : abcd
Input String : abcd
Output String : abcd
Input String : //abcd/
Output String : /abcd
Will work.
Matches the first
(^/)?means match 0 or 1 ‘/’ at the beginning of the string, and(/$)?means match 0 or 1 ‘/’ at the end of the string.Make the regex
"(^/*)?(/*$)?"to support matching multiple ‘/’: