fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. String regex = "-a-([^\\?]+)\\?";
  12. String string = "location/city/home-a-berlin?/someNewAdress\n";
  13.  
  14. Pattern pattern = Pattern.compile(regex);
  15. Matcher matcher = pattern.matcher(string);
  16.  
  17. if (matcher.find()) {
  18. System.out.println(matcher.group(1));
  19. }
  20. }
  21. }
Success #stdin #stdout 0.1s 48144KB
stdin
Standard input is empty
stdout
berlin