Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem matching regex pattern in Android

I am trying to search this string:

,"tt" : "ABC","r" : "+725.00","a" : "55.30",

For:

"r" : "725.00"

And here is my current code:

Pattern p = Pattern.compile("([r]\".:.\"[+|-][0-9]+.[0-9][0-9]\")");
Matcher m = p.matcher(raw_string);

I've been trying multiple variations of the pattern, and a match is never found. A second set of eyes would be great!

like image 594
joet3ch Avatar asked Dec 23 '22 01:12

joet3ch


1 Answers

Your regexp actually works, it's almost correct

Pattern p = Pattern.compile("\"[r]\".:.\"[+|-][0-9]+.[0-9][0-9]\"");
Matcher m = p.matcher(raw_string);
if (m.find()){
    String res = m.toMatchResult().group(0);
}
like image 175
Fedor Avatar answered Dec 28 '22 10:12

Fedor