日期:2014-05-20 浏览次数:20694 次
final String friendList = "var friends=[{\"id\":422727123,\"vip\":false,\"selected\":true,\"mo\":false,\"name\":\"\u9648\u671b\u6797\",\"head\":\"http:\\/\\/hdn.xnimg.cn\\/photos\\/hdn121\\/20111020\\/2120\\/tiny_dfoU_59555d019117.jpg\",\"groups\":[]},{\"id\":123456789,\"vip\":false,\"selected\":false,\"mo\":false,\"name\":\"\u9648\u76ca\u714c\",\"head\":\"http:\\/\\/hdn.xnimg.cn\\/photos\\/hdn121\\/20130423\\/0105\\/tiny_Vhoj_f8eb00022ee4111a.jpg\",\"groups\":[]}];";
final String regex = "\"id\":(\\d{9}),\"vip\":.*\"name\":\"(.*)\",\"head\":\"(.*.jpg)\",\"";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(friendList);
int i;
while(matcher.find())
{
System.out.println("GroupCount : "+ matcher.groupCount());
System.out.println("Start : "+matcher.start());
System.out.println("End : "+matcher.end());
for(i = 0;i<=matcher.groupCount();i++)
{
System.out.println(matcher.group(i));
}
}
final String friendList = "var friends=[{\"id\":422727123,\"vip\":false,\"selected\":true,\"mo\":false,\"name\":\"\u9648\u671b\u6797\",\"head\":\"http:\\/\\/hdn.xnimg.cn\\/photos\\/hdn121\\/20111020\\/2120\\/tiny_dfoU_59555d019117.jpg\",\"groups\":[]},{\"id\":123456789,\"vip\":false,\"selected\":false,\"mo\":false,\"name\":\"\u9648\u76ca\u714c\",\"head\":\"http:\\/\\/hdn.xnimg.cn\\/photos\\/hdn121\\/20130423\\/0105\\/tiny_Vhoj_f8eb00022ee4111a.jpg\",\"groups\":[]}];";
final String regex = "\"id\":(\\d{9}),\"vip\":.*?\"name\":\"(.*?)\",\"head\":\"(.*?.jpg)\",\"";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(friendList);
int i;
while(matcher.find())
{
System.out.println("GroupCount : "+ matcher.groupCount());
System.out.println("Start : "+matcher.start());
System.out.println("End : "+matcher.end());
for(i = 0;i<=matcher.groupCount();i++)
{
System.out.println(matcher.group(i));
}
}