fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. List<String> strs = Arrays.asList("foo/bar/Samsung-Galaxy/a-b/1","foo/bar/Samsung-Galaxy/c-d/1#P2","foo.com/Samsung-Galaxy/9090/c-d/69");
  11. String pattern = "^.*/(?:a-b|c-d|e-f)/[^/]*?([0-9]+)$";
  12. for (String s : strs) {
  13. System.out.println(s + ": \"" + s.replaceFirst(pattern, "$1") + "\"");
  14. }
  15.  
  16. }
  17. }
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
foo/bar/Samsung-Galaxy/a-b/1: "1"
foo/bar/Samsung-Galaxy/c-d/1#P2: "2"
foo.com/Samsung-Galaxy/9090/c-d/69: "69"