I have an XML style string that I am trying to get a groups out of in a while(matcher.find()){} loop. Here is the regex I am using:
<myset setName="(.+?)">(.*?)</myset>
when converted for use in java:
Pattern setPattern = Pattern.compile("<myset setName=\"(.+?)\">(.*?)</myset>");
Matcher matcher = setPattern.matcher(targetString);
while(matcher.find()){
Log.i(TAG, "First group: " + $1 + " Second group: " + $2);
}
$1 is the setName -- This should always be at least 1 character.
$2 is everything (or nothing) in between the opening and closing tags. This can be 0 or more characters.
If I do a find() on the string:
<myset setName="test"><lots of stuff in this subtag /></myset>
It works perfectly, with $1 being assigned test and $2 assigned <lots of stuff in this subtag />
However, if I do a find() on this string:
<myset setName="test"><lots of stuff in this subtag /></myset><myset setName="test2"><more stuff in this subtag /></myset>
Then $1 matches test and $2 matches <lots of stuff in this subtag /></myset><myset setName="test2"><more stuff in here />
The intended behavior is the first find() should have $1 match test and $2 match <lots of stuff in this subtag />. Then the 2nd find() should have $1 match test2 and $2 match <more stuff in this subtag />.
I am sure I am overlooking something obvious. Thanks!