Trim leading or trailing characters from a string?
You could use
Leading:
System.out.println("//test/me".replaceAll("^/+", ""));
Trailing:
System.out.println("//test/me//".replaceAll("/+$", ""));
You can use Apache StringUtils.stripStart to trim leading characters, or StringUtils.stripEnd to trim trailing characters.
For example:
System.out.println(StringUtils.stripStart("//test/me", "/"));
will output:
test/me
Note that if for some reason you can't use the whole StringUtils library, you could just rip out the relevant parts, as detailed here: