0

I am trying to use relaceAll to replace a space with "\\s+" but instead of replacing with desired characters it's considering it as space, Here is my code:

String text = "hello  world !".replaceAll("\\s+", "\\\\s+");

My expected output is:

hello\\s+world\\s+!
fean
  • 546
  • 4
  • 12
  • 37
  • 1
    If you want to replace **a space**, you could use```replace(" ","\\\\s+")```, but it doesn't look like that is actually what you want. – khelwood Mar 28 '18 at 22:31
  • 2
    @khelwood 1) don't post answers as comments 2) `'\\\\s+` isn't a character... – corsiKa Mar 28 '18 at 22:32

0 Answers0