import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "[:]\\s(\\\".*\\\")|\\d+";
final String string = "{\n"
+ " \"code\": 0,\n"
+ " \"data\": {\n"
+ " \"album\": {\n"
+ " \"count\": 2,\n"
+ " \"itemlist\": [\n"
+ " {\n"
+ " \"docid\": \"24100646\",\n"
+ " \"id\": \"24100646\",\n"
+ " \"mid\": \"002mPgSG01LLtu\",\n"
+ " \"name\": \"无名的人\",\n"
+ " \"pic\": \"http://y.gtimg.cn/music/photo_new/T002R180x180M000002mPgSG01LLtu_1.jpg\",\n"
+ " \"singer\": \"毛不易\"\n"
+ " },\n"
+ " {\n"
+ " \"docid\": \"3834888\",\n"
+ " \"id\": \"3834888\",\n"
+ " \"mid\": \"0026ttFc17IeE3\",\n"
+ " \"name\": \"无问\",\n"
+ " \"pic\": \"http://y.gtimg.cn/music/photo_new/T002R180x180M0000026ttFc17IeE3_1.jpg\",\n"
+ " \"singer\": \"毛不易\"\n"
+ " }\n"
+ " ],\n"
+ " \"name\": \"专辑\",\n"
+ " \"order\": 2,\n"
+ " \"type\": 3\n"
+ " },\n"
+ " \"mv\": {\n"
+ " \"count\": 2,\n"
+ " \"itemlist\": [\n"
+ " {\n"
+ " \"docid\": \"1449642\",\n"
+ " \"id\": \"1449642\",\n"
+ " \"mid\": \"001UwAbv4H9QVZ\",\n"
+ " \"name\": \"牧马城市\",\n"
+ " \"singer\": \"毛不易\",\n"
+ " \"vid\": \"k002671le5d\"\n"
+ " },\n"
+ " {\n"
+ " \"docid\": \"1352908\",\n"
+ " \"id\": \"1352908\",\n"
+ " \"mid\": \"003bjsSu20ltwY\",\n"
+ " \"name\": \"像我这样的人\",\n"
+ " \"singer\": \"毛不易\",\n"
+ " \"vid\": \"y0026hr4b5e\"\n"
+ " }\n"
+ " ],\n"
+ " \"name\": \"MV\",\n"
+ " \"order\": 3,\n"
+ " \"type\": 4\n"
+ " },\n"
+ " \"singer\": {\n"
+ " \"count\": 2,\n"
+ " \"itemlist\": [\n"
+ " {\n"
+ " \"docid\": \"1507534\",\n"
+ " \"id\": \"1507534\",\n"
+ " \"mid\": \"001BHDR33FZVZ0\",\n"
+ " \"name\": \"毛不易\",\n"
+ " \"pic\": \"http://y.gtimg.cn/music/photo_new/T001R150x150M000001BHDR33FZVZ0_3.jpg\",\n"
+ " \"singer\": \"毛不易\"\n"
+ " },\n"
+ " {\n"
+ " \"docid\": \"4417724\",\n"
+ " \"id\": \"4417724\",\n"
+ " \"mid\": \"000pEm1i1BkmuD\",\n"
+ " \"name\": \"毛不易的留声机\",\n"
+ " \"pic\": \"http://y.gtimg.cn/music/photo_new/T001R150x150M000000pEm1i1BkmuD_1.jpg\",\n"
+ " \"singe\": \"毛不易的留声机\"\n"
+ " }\n"
+ " ],\n"
+ " \"name\": \"歌手\",\n"
+ " \"order\": 1,\n"
+ " \"type\": 2\n"
+ " },\n"
+ " \"song\": {\n"
+ " \"count\": 4,\n"
+ " \"itemlist\": [\n"
+ " {\n"
+ " \"docid\": \"203514624\",\n"
+ " \"id\": \"203514624\",\n"
+ " \"mid\": \"00375L600p9sxv\",\n"
+ " \"name\": \"像我这样的人\",\n"
+ " \"singer\": \"毛不易\"\n"
+ " }\n"
+ " {\n"
+ " \"docid\": \"203451421\",\n"
+ " \"id\": \"203451421\",\n"
+ " \"mid\": \"003kLvu04bLGzi\",\n"
+ " \"name\": \"消愁\",\n"
+ " \"singer\": \"毛不易\"\n"
+ " }\n"
+ " {\n"
+ " \"docid\": \"213224236\",\n"
+ " \"id\": \"213224236\",\n"
+ " \"mid\": \"000uhMwj387EBp\",\n"
+ " \"name\": \"牧马城市\",\n"
+ " \"singer\": \"毛不易\"\n"
+ " }\n"
+ " {\n"
+ " \"docid\": \"336582682\",\n"
+ " \"id\": \"336582682\",\n"
+ " \"mid\": \"002QhULf16tWw1\",\n"
+ " \"name\": \"无名的人\",\n"
+ " \"singer\": \"毛不易\"\n"
+ " }\n"
+ " ],\n"
+ " \"name\": \"单曲\",\n"
+ " \"order\": 0,\n"
+ " \"type\": 1\n"
+ " }\n"
+ " },\n"
+ " \"subcode\": 0\n"
+ "}";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html