  public String extractTweet(String html) {
    Preconditions.checkNotNull(html);
    Matcher matcher = TWEET_PATTERN.matcher(html);
    if (!matcher.find()) {
      return null;
    }
    String tweet = matcher.group(1);
    matcher = URL_PATTERN.matcher(tweet);
    StringBuffer rawsb = new StringBuffer();
    while (matcher.find()) {
      HashMap<String,String> urls = new HashMap<String,String>();
      urls.put(matcher.group(1), matcher.group(2));
      urls.put(matcher.group(3), matcher.group(4));
      String deu = urls.containsKey("data-expanded-url") ? urls.get("data-expanded-url") : "";
      String href = urls.containsKey("href") ? urls.get("href") : "";
      if (!deu.equals(""))
        matcher.appendReplacement(rawsb, deu);
      else if (!href.equals(""))
        matcher.appendReplacement(rawsb, href);
      else
        matcher.appendReplacement(rawsb, "$0"); 
    }
    matcher.appendTail(rawsb);
    tweet = rawsb.toString();
    tweet = tweet.replaceAll("<(.|\n)*?>", "").replaceAll("[\n\r]", "").replaceAll("[\t]", " ").trim();
    tweet = StringEscapeUtils.unescapeHtml(tweet);
    return tweet;
  }

  public String extractTweet(String html) {
    Preconditions.checkNotNull(html);
    Matcher matcher = TWEET_PATTERN.matcher(html);
    if (!matcher.find()) {
      return null;
    }
    String tweet = matcher.group(1);
    matcher = URL_PATTERN.matcher(tweet);
    StringBuffer rawsb = new StringBuffer();
    while (matcher.find()) {
      HashMap<String,String> urls = new HashMap<String,String>();
      urls.put(matcher.group(1), matcher.group(2));
      urls.put(matcher.group(3), matcher.group(4));
      String deu = urls.containsKey("data-expanded-url") ? urls.get("data-expanded-url") : "";
      String href = urls.containsKey("href") ? urls.get("href") : "";
      if (!deu.equals(""))
        matcher.appendReplacement(rawsb, deu.replaceAll("\\$", "\\\\\\$"));
      else if (!href.equals(""))
        matcher.appendReplacement(rawsb, href.replaceAll("\\$", "\\\\\\$"));
      else
        matcher.appendReplacement(rawsb, "$0"); 
    }
    matcher.appendTail(rawsb);
    tweet = rawsb.toString();
    tweet = tweet.replaceAll("<(.|\n)*?>", "").replaceAll("[\n\r]", "").replaceAll("[\t]", " ").trim();
    tweet = StringEscapeUtils.unescapeHtml(tweet);
    return tweet;
  }
