0

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:

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

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

5
  • Is that really a string? It looks like an array to me. Commented Jan 19, 2011 at 19:36
  • 1
    I think he means "{\"Name\", \"Surname\", \"Age\", \"Other string with letters and numbers\"}" Commented Jan 19, 2011 at 19:37
  • 3
    Any character list can be a string.. if he says this is the string, maybe this is the string! Commented Jan 19, 2011 at 19:39
  • yes of course it was a string :D i hope that now is clearer ;) Commented Jan 19, 2011 at 19:40
  • Where's this data coming from? Is it JSON? If so, there are several libraries out there to aid in marshalling/unmarshalling JSON content. Commented Jan 19, 2011 at 19:43

3 Answers 3

4

This will match all the terms you specify:

\"(.*?)\"

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

Sign up to request clarification or add additional context in comments.

Comments

1
    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

3 Comments

You've forgotten to remove double quotes from the input string
Perhaps he only asked for a regex because he didn't know there's a perfectly good split() method? :)
yes, i knew about the String's methods :) but i was searching for regex
1

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

1 Comment

Nothing. That is perfectly fine sir.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.