This code below will show how to strip trailing spaces in string using a regex.
@Test public void strip_trailing_spaces() { String removeSpace = " spaces "; String leftTrim = removeSpace.replaceAll("\s+$", ""); assertEquals(" spaces", leftTrim); }