user1667162
user1667162

Reputation:

Regex to get text between " symbols

i got this string:

"streamUrl":"http://media.mysite.com/stream/WF9bRDueA0sm?stream_token=f2EmQ",

Ok, now i have a function in java

 Pattern p = Pattern.compile(
                        "<row><column>(.*)</column></row>",
                        Pattern.DOTALL
                    );

                Matcher matcher = p.matcher(code); //That is the code up, "streamUrl...

                if(matcher.matches()){
                        testo2.setText(matcher.group(1));

            }

Ok now i have to change the Regex Pattern to get text between

"streamUrl":"

and

",

That's are special char and i don't know how to add it to the pattern, i tryied

Pattern.compile(
                    "Pattern.compile(
                    ""streamUrl":"(.*)",",
                    Pattern.DOTALL
                );(.*)</column></row>",
                    Pattern.DOTALL
                );

But it's not working, can someone help me? i need to get this: http://media.mysite.com/stream/WF9bRDueA0sm?stream_token=f2EmQ Thanks in advice, matteo :)

Upvotes: 0

Views: 1049

Answers (2)

Mukesh Soni
Mukesh Soni

Reputation: 6668

You can try using JSONTokener

try  {
    JSONTokener tokener = new JSONTokener(yourString);
    JSONObject jsonObj = (JSONObject) tokener.nextValue();
    String output = jsonObj.getString("streamUrl");
} catch (JSONException e) {
    Log.v("Logtag", "Problem in decoding json");
    e.printStackTrace();
}

Upvotes: 5

gtgaxiola
gtgaxiola

Reputation: 9331

The way you match it is:

String regex = "\"streamUrl\":\"(.*)\",";
Pattern p = Pattern.compile(regex);

But as stated in the comments you are way better using JSON.

Upvotes: 2

Related Questions