fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.regex.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13.  
  14.  
  15. Scanner scanner = new Scanner(System.in);
  16. scanner.useDelimiter("[^\\w']+");
  17. String separator;
  18. Pattern rx = Pattern.compile(".I \\d");
  19. while (scanner.hasNext()){
  20. separator = scanner.findInLine(rx);
  21. if (separator!= null) {
  22. int num = Integer.valueOf(separator.substring(3));
  23. System.out.println("Found: " + separator+", article number: "+num);
  24. scanner.nextLine();
  25. scanner.nextLine();
  26. }
  27. System.out.println(scanner.nextLine());
  28. }
  29. scanner.close();
  30.  
  31.  
  32.  
  33. }
  34. }
Success #stdin #stdout 0.1s 380736KB
stdin
.I 1
.W
this is article one.         
.I 2
.W
this is article two.                   
.I 3
.W
this is article three. 
stdout
Found: .I 1, article number: 1
this is article one.         
Found: .I 2, article number: 2
this is article two.                   
Found: .I 3, article number: 3
this is article three.