The 's' replaces a single Room match at a time though the 's+' replaces the whole Room sequence at the same time with the 2nd parameter. Having said that x.replaceAll("\s+", ""); will likely be much more successful strategy for trimming spaces (if string might have a number of contiguous Areas) https://mr-mushies-gummies65318.blogkoo.com/the-5-second-trick-for-mantra-mushroom-chocolate-bars-50941395