fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.*;
  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. String text ="2.10 Add nodev Option to Removable Media Partitions (Scored)"
  14. +"Profile Description:Set nodev on removable media to prevent character and "
  15. +"block special devices that are present"
  16. +", on the removable media from being treated as device files. ";
  17.  
  18. Pattern p = Pattern.compile("((\\d+(?:\\.\\d+)?)?.*\\(Scored\\))\\n?(.*)", Pattern.DOTALL);
  19. Matcher m = p.matcher(text);
  20. if (m.matches()) {
  21. System.out.println("The text matches");
  22. System.out.printf("Title : %s%n", m.group(1));
  23. System.out.printf("Chapter : %s%n", m.group(2));
  24. System.out.printf("Content : %s%n", m.group(3));
  25. }
  26. }
  27. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
The text matches
Title : 2.10 Add nodev Option to Removable Media Partitions (Scored)
Chapter : 2.10
Content : Profile  Description:Set nodev on removable media to prevent character and block special devices that are present, on the removable media from being treated as device files.