开发者

Splitting String with Regular Expression

Hi I really don't understand Regular Expressions :P

This is the input string:

"{\"Name\", \"Surname\", \"Age\", 开发者_StackOverflow中文版\"Other string with letters and numbers\"}"

And this is the output array of strings that i want:

  • Name;
  • Surname;
  • Age;
  • Other string with letters and numbers

In other words, i have to eliminate ", { and ,


This will match all the terms you specify:

\"(.*?)\"

Working example: http://rubular.com/r/A91DetXakU


    String str = "{\"Name\", \"Surname\", \"Age\", \"Other string with letters and numbers\"}";
    String strArr[] = str.replaceAll("\\}|\\{|\"", "").split(",");
    for (String tmpStr : strArr) {
        System.out.println(tmpStr);

    }

Output:

Name
Surname
Age
Other string with letters and numbers

  • IdeOneDemo


What is wrong with yourString.split("[\\", {}]");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜