我有字符串"a,b,c,d,,,,, "
, ",,,,a,,,,"
我想将这些字符串分别转换为"a,b,c,d"
和",,,,a"
。
我正在编写一个正则表达式来实现这一点。我的Java代码如下:
public class TestRegx{
public static void main(String[] arg){
String text = ",,,a,,,";
System.out.println("Before " +text);
text = text.replaceAll("[^a-zA-Z0-9]","");
System.out.println("After " +text);
}}
但是这会移除这里的所有逗号。
如何编写以实现上述所示?
()
来捕获,
。 - TheLostMind+
量词代替*
量词怎么样? - Jonny 5