【发布时间】:2015-08-28 04:49:41
【问题描述】:
我有字符串"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);
}}
但是这里删除了所有的逗号。
如上给出的如何写这个来实现?
【问题讨论】:
标签: java regex string str-replace