I just wanted to replace sequence of a character '\' (i.e. consecutive like \\\) to single '\' in Java. If possible I dont want to iterate with for loop all. Is there anything possible with regex to find and replace? Because in my case I will get lots of input like this if user gave in application for each and every time I have to validate and replace all \ character.
Can anyone help me in this context.
input is : \\\\Program Files\\Microsoft Games\\\\\Chess\\\Chess.exe
output which I expect is : \Program Files\Microsoft Games\Chess\Chess.exe
static String replaceConsecutiveBackslash(String input) {
return input.replaceAll("\\\\{2,}", "\\\\");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With