import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(.)";
final String string = "Work\n"
+ "Work\n"
+ "Fire\n"
+ "Global{\"dmids\":[200000298206588]}\n"
+ "{\"dmids\":[200000298207769,200000315647883]}\n"
+ "{\"dmids\":[200000298207847,200000298559762,200000298729095,200000298937045,200000299376139,200000337459486,200000339993204,2000000298149778]}\n"
+ "{\"dmids\":[200000298208329,200000298316016,200000298560524,200000300915842,2000000298179810,2000000298180861]}\n"
+ "{\"dmids\":[200000298208335,200000298316025,200000298560517,200000300915858,2000000298179808,2000000298180858]}\n"
+ "{\"dmids\":[200000298208343,200000298316014,200000298560521,200000300915848,2000000298179798,2000000298180857]}\n"
+ "{\"dmids\":[200000298210597,200000299898455,200000299949910,200000304060818,200000305323250,2000000298190262]}";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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