Oneiros
Oneiros

Reputation: 4378

Splitting String with Regular Expression

Hi I really don't understand Regular Expressions :P

This is the input string:

"{\"Name\", \"Surname\", \"Age\", \"Other string with letters and numbers\"}"

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

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

Upvotes: 0

Views: 1187

Answers (3)

Jochen Bedersdorfer
Jochen Bedersdorfer

Reputation: 4122

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

Upvotes: 1

Jigar Joshi
Jigar Joshi

Reputation: 240976

    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

Upvotes: 1

Kyle Wild
Kyle Wild

Reputation: 8915

This will match all the terms you specify:

\"(.*?)\"

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

Upvotes: 4

Related Questions