Remove or replace a backslash with replaceAll regex in Java

Sometimes logical solutions can be unintuitive. If you want to replace a single backslash in Java using replaceAll there are multiple layers of escaping that leads to four backslashes as an argument for replaceAll.

 

 

(172 Posts)

20 years of coding and working as software engineer but I am still eager to learn more. I am very passionate when it comes to open source, Linux and Java. But I made my peace with Windows long ago to fully enjoy my PC gaming hobby. I have a soft spot for 90s electronic music and Babylon 5. In the evenings you will find me roaming the endless space in Warframe (IGN k05h).

One thought on “Remove or replace a backslash with replaceAll regex in Java

Leave a Reply

Your email address will not be published. Required fields are marked *