You could use
Leading:
System.out.println("//test/me".replaceAll("^/+", ""));
Trailing:
System.out.println("//test/me//".replaceAll("/+$", ""));
More Related Contents:
- Trim characters in Java
- How can I trim beginning and ending double quotes from a string?
- How to remove only trailing spaces of a string in Java and keep leading spaces?
- Difference between String trim() and strip() methods in Java 11
- What is a good alternative of LTRIM and RTRIM in Java?
- Simple way to repeat a string
- Difference between string object and string literal [duplicate]
- When should we use intern method of String on String literals
- How to convert Strings to and from UTF8 byte arrays in Java
- Left padding a String with Zeros [duplicate]
- What makes reference comparison (==) work for some strings in Java?
- How do I trim a file extension from a String in Java?
- How to find a whole word in a String in Java?
- How to convert String to long in Java?
- Reversing a String with Recursion in Java
- getString Outside of a Context or Activity
- Java: String concat vs StringBuilder – optimised, so what should I do?
- String array initialization in Java [duplicate]
- Extract the difference between two strings in Java
- Printing reverse of any String without using any predefined function?
- Check if string ends with certain pattern
- How do format a phone number as a String in Java?
- Verify if String is hexadecimal
- Is there a memory-efficient replacement of java.lang.String?
- What is the most efficient way to convert an int to a String?
- String.replaceAll is considerably slower than doing the job yourself
- Remove all occurrences of \ from string
- Is there a difference between String concat and the + operator in Java? [duplicate]
- Java String literal pool and string object
- Java: Checking equality of arrays (order doesn’t matter)