4
String str=",Name=Tom,Age=23,something=something,roll=1,somethng=55,"

I want to remove all those key value pairs from the string whose value is a number.

Now i am doing something like this

    Pattern p = Pattern.compile(",[^=]*?=([^,]*),");
    Matcher m = p.matcher(str);
    String result = "";
    while (m.find()) {
        if (!isNumeric(m.group(1))) {
            result += m.group(0);
        }

    }
    System.out.println(result);

The expected output is

",Name=Tom,something=something,"

But now i am getting

",Name=Tom,,something=something,"

Please help.

4

1 回答 1

5
result=str.replaceAll(",[^=]*?=[0-9]+", "");
System.out.println(result);

你可以试试这个。

于 2013-07-08T15:42:09.903 回答