fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. class Main {
  5. public static final String EXAMPLE_TEST = "s:64:\"first string\" some content s:64:\"second string\" some other content s:64:\"third string\" some content s:64:\"fourth string\"";
  6.  
  7. public static void main(String[] args) {
  8. Pattern pattern = Pattern.compile("s:64:\"(.*?)\"");
  9. Matcher matcher = pattern.matcher(EXAMPLE_TEST);
  10. // Check all occurance
  11. int count = 0;
  12. while (matcher.find() && count++ < 2) {
  13. System.out.println("Group : " + matcher.group(1));
  14. }
  15. }
  16. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
Group : first string
Group : second string