regex - Delete all the space at end of each line in Java -
i'm trying delete spaces , tabs @ end of lines.
i use following methods:
string.replace("\\s+$", ""); here, "\s+$" regex expression
it seems it' right. fact not delete it.
the string is:
               a) aaaaaa.                                    b) bbbbb.            c) cccccc.            d) ddddd. 
like this:
string.replaceall("\\s+$", ""); - string#replace()not take regex argument.
- you need double escape \s
edit: yes work:
public static void main(final string[] args) {     final string = "     aaaaaaaa             ";     system.out.println(a.replaceall("\\s+$", "")); } maybe confusion think a.replaceall() modify string a. strings in java immutable (they cannot change). a.replaceall() return modified string.
edit2: if you're using multiline string, "\\s+[$\n]" regex should work.
Comments
Post a Comment