title: Detect and extract url from a string?
body: <p>This is a easy question,but I just don't get it.
  I want to detect url in a string and replace them with a shorten one.</p>
  
  <p>I found this expression from stackoverflow,But the result is just <code>http</code> </p>
  
  <pre><code>Pattern p = Pattern.compile("\\b(https?|ftp|file)://[-a-zA-Z0-9+&amp;@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&amp;@#/%=~_|]",Pattern.CASE_INSENSITIVE);
          Matcher m = p.matcher(str);
          boolean result = m.find();
          while (result) {
              for (int i = 1; i &lt;= m.groupCount(); i++) {
                  String url=m.group(i);
                  str = str.replace(url, shorten(url));
              }
              result = m.find();
          }
          return html;
  </code></pre>
  
  <p>Is there any better idea?</p>