The 's' replaces one particular Area match at any given time even so the 's+' replaces the whole House sequence simultaneously with the second parameter. On the other hand x.replaceAll("\s+", ""); is going to be a lot more efficient technique for trimming spaces (if string might have several contiguous Areas) https://manuelqjzqe.shotblogs.com/the-best-side-of-s-45409691