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. Pattern p = Pattern.compile("^(.*?)_(CH|IT|FR|GB)-(EN|IT|FR|DE)_(.*)$");
  14. Scanner sc = new Scanner(System.in);
  15. String input;
  16. while (sc.hasNextLine()) {
  17. input = sc.nextLine();
  18. Matcher m = p.matcher(input);
  19. if (m.matches()) {
  20. String[] result = {m.group(1), m.group(2), m.group(3), m.group(4) };
  21. System.out.println("Matched : " + Arrays.toString(result));
  22. }
  23. else {
  24. System.out.println("No match for " + input);
  25. }
  26. }
  27. }
  28. }
Success #stdin #stdout 0.13s 37592KB
stdin
MyPrefix_CH-DE_ProductName.pdf
my-prefix_FR-FR_mon_produit-1.3.pdf
stdout
Matched : [MyPrefix, CH, DE, ProductName.pdf]
Matched : [my-prefix, FR, FR, mon_produit-1.3.pdf]