This url link is valid https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8# need to remove all numeric characters, and that the output of the link was after the first character ? and separated by the parameters = or - , the output of the link should be sourceid chrome instant ion espv ie UTF . I want to solve through regular expressions, so far I could only remove all the characters.

 String url = "https://www.google.ru/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8# "; String regexp1 = "([?\\.\\&\\:\\;\\/\\=\\-\\#]+)"; // используем Паттерн, компилируем регулярное выражение Pattern pattern1 = Pattern.compile(regexp1); // делаем матчер по созданному паттерну и кидаем в конструктор наш URL. Matcher matcher1 = pattern1.matcher(url); String output = matcher1.replaceAll(" "); System.out.println(output); 

    2 answers 2

    If you don’t pervert regularly, then you can:

     public static Map<String, List<String>> splitQuery(URL url) throws UnsupportedEncodingException { final Map<String, List<String>> query_pairs = new LinkedHashMap<String, List<String>>(); final String[] pairs = url.getQuery().split("&"); for (String pair : pairs) { final int idx = pair.indexOf("="); final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair; if (!query_pairs.containsKey(key)) { query_pairs.put(key, new LinkedList<String>()); } final String value = idx > 0 && pair.length() > idx + 1 ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8") : null; query_pairs.get(key).add(value); } return query_pairs; } 

    The method will return the map with the parameters and values ​​thereof. From it it is already possible to discard all the values-numbers.

    Under the link there are other solutions of varying degrees of simplicity.

      You can do this:

       String url = "https://www.google.ru/webhp?sourc23eid=chrome-instant&ion=1&espv=2&ie=UTF-8#"; Pattern pattern = Pattern.compile("[\\w]+=([\\w-]+)&?"); Matcher matcher = pattern.matcher(url); while (matcher.find()) System.out.println(matcher.group(1)); 

      The output will be as follows:

      chrome-instant
      one
      2
      UTF-8