fork download
  1. import java.util.regex.*;
  2. import java.lang.*;
  3.  
  4. class Main
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String str = "STARTText blah, blah\n" +
  9. "\\ next line with more text, but the leading backslash\n" +
  10. "\\ next line with more text, but the leading backslash\n" +
  11. "\\ next line with more text, but the leading backslash\n" +
  12. "foo\n" +
  13. "bar\n";
  14.  
  15. Pattern p = Pattern.compile("(?m)^STARTText.*?(\\r?\\n)(?:^\\\\.*?\\1)+");
  16. Matcher m = p.matcher(str);
  17. if (m.find())
  18. System.out.printf("Matched: %s%n", m.group(0));
  19. }
  20. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
Matched: STARTText blah, blah
\    next line with more text, but the leading backslash
\    next line with more text, but the leading backslash
\    next line with more text, but the leading backslash