fork(1) download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String str = " Door 51 text1 Door 61 text2 Door 10 text3";
  11. Pattern pattern = Pattern.compile("\\bDoor\\s+\\d+(.*?)(?=\\bDoor\\s+\\d+|$)");
  12. Matcher matcher = pattern.matcher(str);
  13. while (matcher.find()) {
  14. System.out.println(matcher.group(1));
  15. }
  16. }
  17. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
 text1 
 text2 
 text3