String content = "1. Case Jurisdiction Issue {" Label 1 "Default content 1} Test test test test Testing {" Label 2 "Default content 2} Test test test test Test testing test Test testing testing test test"; String pattern = "\\{(". *? ") ([^,,].*?) \\}"; Pattern P = pattern.compile (pattern); Matcher Matcher = p.matcher (content); while (Matcher.find ()) {String group = Matcher.group (); int start = Matcher.start (); int end = Matcher.end (); SYSTEM.OUT.PRINTLN (group + "," + Start + "," + End + "\n===\n"); } String Content1 = "{" label "Default content}"; String pattern1 = "\\{" ([\\s\\s]*) "([\\s\\s]*) \ \}"; Pattern P1 = Pattern.compile (PATTERN1); Matcher matcher1 = P1.matcher (content1); while (Matcher1.find ()) {int matchcount = Matcher1.groupcount (); while (matchcount >= 0) {String group = Matcher1.group (MatchCount); int start1 = Matcher1.start (MatchCount); int end1 = Matcher1.end (MatchCount); SYSTEM.OUT.PRINTLN (group + "," +Start1 + "," + end1); matchcount--; } }
JAVA Regular Expressions