Want to use Java String.replaceAll(regex, "") to remove all leading spaces of each line in a multi-line text string. if possible remove all carriage-returns as well. What the "regex" should be?
1 Answer
Converting my comment to answer so that solution is easy to find for future visitors.
You may use regex replacement in Java:
str = str.replaceAll("(?m)^\\s+|\\s+$", "");
RegEx Details:
(?m): EnableMULTILINEmode so that^and$are matched in every line.^\\s+: Match 1+ whitespaces at line start|: OR\\s+$: Match 1+ whitespaces before line end