It is necessary from type links

https://www.google.com/url?rct=j&sa=t&url=http://tower43.ru/b0013232&ct=ga&cd=CAEYACoTMzUwODg1NjAwNzEwMDkwNjAyMjIcM2Q5YzNlZTJkOGNlNDNhNTpydTplbjpSVTpSTA&usg=AFQjCNH-ApyoRaD_cwKMe5tj6JwiB6Qpcg 

Get links of the form:

 tower43.ru/b0013232 

With the help of the service I wrote a regular list that does not work in java-code (returns false)

  String pattern = Pattern.quote("/(\\S)(https?:[\\S]*)(&ct=ga&cd=)/"); Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(url); boolean pure_url = m.find(); System.out.println(pure_url); 

Moreover, the site writes that there are coincidences.

  • m.find() returns true / false . You need to use .group(1) - if (m.find()) { System.out.println(m.group(1)); } if (m.find()) { System.out.println(m.group(1)); } - Wiktor Stribiżew
  • Regulars are not needed. Use the built-in tools to parse the url and pull the url parameter with Query - so - KoVadim

1 answer 1

Try so

  String str = ...; Pattern pattern = Pattern.compile("^.+?url=(http[s]?://[\\w.]+.*?)&"); Matcher matcher = pattern.matcher(str); if (matcher.find()) System.out.println(matcher.group(1));