fork(11) 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 version = "1.0.1-RC";
  11. Pattern versionPattern = Pattern.compile("([1-9]\\d*)\\.(\\d+)\\.(\\d+)(?:-([a-zA-Z0-9]+))?");
  12. Matcher matcher = versionPattern.matcher(version);
  13.  
  14. if (matcher.matches()) {
  15.  
  16. System.out.println("matching version is: " + matcher.group(0));
  17. System.out.println("major #: " + matcher.group(1));
  18. System.out.println("minor #: " + matcher.group(2));
  19. System.out.println("patch #: " + matcher.group(3));
  20. System.out.println("qualifier: " + matcher.group(4) + "\n\n\n");
  21.  
  22. }
  23. }
  24. }
Success #stdin #stdout 0.15s 36436KB
stdin
Standard input is empty
stdout
matching version is: 1.0.1-RC
major #: 1
minor #: 0
patch #: 1
qualifier: RC