Regex for special characters in java

后端 未结 6 1612
说谎
说谎 2021-01-06 10:09
public static final String specialChars1= \"\\\\W\\\\S\";
String str2 = str1.replaceAll(specialChars1, \"\").replace(\" \", \"+\");

public static final String speci         


        
6条回答
  •  离开以前
    2021-01-06 10:25

    @npinti

    using "\w" is the same as "\dA-Za-z"

    This worked for me:

    String result = str.replaceAll("[^\\w ]", "").replaceAll("\\s+", "+");
    

提交回复
热议问题