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. static final Pattern NUM_TITLE = Pattern.compile("F\\{([\\d\\s&]*)\\}#\\{([\\s\\w&]*)\\}");
  12. //compile once
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. String [] test = {"F{403}#{Title1}",
  16. "F{}#{}", // will be matched because you use *
  17. "F{123123 2312321}#{asdasd sdads www}",
  18. "F{123123 2312321}#{asdasd sdads &&www}",
  19. };
  20. for(String subjectString : test){
  21. Matcher regexMatcher = NUM_TITLE.matcher(subjectString);
  22. if (regexMatcher.find()) {
  23. System.out.println("Num: " + regexMatcher.group(1) + " Title: " + regexMatcher.group(2));
  24. }
  25. }
  26. }
  27. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
Num: 403 Title: Title1
Num:  Title: 
Num: 123123 2312321 Title: asdasd sdads	www
Num: 123123 2312321 Title: asdasd sdads	&&www