Regex for special characters in java

后端 未结 6 1641
说谎
说谎 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

    This worked for me:

    String result = str.replaceAll("[^\\dA-Za-z ]", "").replaceAll("\\s+", "+");

    For this input string:

    /-+!@#$%^&())";:[]{}\ |wetyk 678dfgh

    It yielded this result:

    +wetyk+678dfgh

提交回复
热议问题