public String evaluate(String urlStr, String partToExtract, String key) {
    if (!partToExtract.equals("QUERY")) {
      return null;
    }

    String query = this.evaluate(urlStr, partToExtract);
    if (query == null) {
      return null;
    }

    if (!key.equals(lastKey)) {
      p = Pattern.compile("(&|^)" + key + "=([^&]*)");
    }

    lastKey = key;
    Matcher m = p.matcher(query);
    if (m.find()) {
      return m.group(2);
    }
    return null;
  }
UDF to extract specfic parts from URL For example,
parse_url('http://facebook.com/path/p1.php?query=1', 'HOST') will return
'facebook.com' For example,
parse_url('http://facebook.com/path/p1.php?query=1', 'PATH') will return
'/path/p1.php' parse_url('http://facebook.com/path/p1.php?query=1', 'QUERY')
will return 'query=1'
parse_url('http://facebook.com/path/p1.php?query=1#Ref', 'REF') will return
'Ref' parse_url('http://facebook.com/path/p1.php?query=1#Ref', 'PROTOCOL')
will return 'http' Possible values are
HOST,PATH,QUERY,REF,PROTOCOL,AUTHORITY,FILE,USERINFO Also you can get a value
of particular key in QUERY, using syntax QUERY:&lt;KEY_NAME&gt; eg: QUERY:k1.
ql/src/java/org/apache/hadoop/hive/ql/udf/UDFParseUrl.java