The 's' replaces one particular Area match at any given time even so the 's+' replaces The entire Area sequence at once with the next parameter. Even so x.replaceAll("\s+", ""); is going to be much more efficient strategy for trimming spaces (if string might have several contiguous Areas) due to https://brookscibud.onesmablog.com/mantra-mushroom-chocolate-an-overview-71853215