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("[\\", {}]");
精彩评论