开发者

Splitting String with Regular Expression

开发者 https://www.devze.com 2023-02-05 08:10 出处:网络
Hi I really don\'t understand Regular Expressions :P This is the input string: \"{\\\"Name\\\", \\\"Surname\\\", \\\"Age\\\", 开发者_StackOverflow中文版\\\"Other string with letters and numbers\\\"}

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

精彩评论

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