Apologies in advance if i am misunderstanding the use of Regex in this context.
I would like to retrieve a repeated field from a String. The string in question looks something like this -
TrendsJSONImpl{asOf=Fri Mar 08 00:04:26 GMT 2013, trendAt=Fri Mar 08 00:04:26 GMT 2013, >trends=[TrendJSONImpl{name='#TheBiggestLies', url='URL', query='%23TheBiggestLies'}, TrendJSONImpl{name='#ICanHonestlySay', >url='URL', query='%23ICanHonestlySay'}, >TrendJSONImpl{name='#EuTenhoUmaQuedaPor', url='URL', query='%23EuTenhoUmaQuedaPor'}, >TrendJSONImpl{name='#CitePessoasExclusivamenteSuas', url='URL', query='%23CitePessoasExclusivamenteSuas'},
From this string, I would like to retrieve the field "name" and add it to a list. This string represents the trending topics on Twitter and is subject to change every time the method that generates it is invoked.
The ideal output would be something like -
#TheBiggestLies
#ICanHonestlySay
#CitePessoasExclusivamenteSuas
Following previous articles on here I have attempted to extract the name field with the following code -
UI.model = new DefaultListModel();
String trendsInfo = //FUNCTIONWHICHRETRIEVESSTRING
Matcher m = Pattern.compile("{name=").matcher(trendsInfo);
Pattern p = Pattern.compile(
"{name='(.*),",
Pattern.DOTALL);
Matcher matcher = p.matcher(trendsInfo);
while (matcher.find()) {
for (int i = 0; i < 20; i++) {
String output = m.group(i);
UI.model.addElement(output);
System.out.println(m.group(i));
}
}
This is unfortunately returning an Illegal Repetition exception and I am not sure how to handle multiple queries of the same field. Any help in this matter would be appreciated.
Thanks for your time!