title: Regular expression to match URLs in Java
body: <p>I use RegexBuddy while working with regular expressions. From its library I copied the regular expression to match URLs. I tested successfully within RegexBuddy. However, when I copied it as Java <code>String</code> flavor and pasted it into Java code, it does not work. The following class prints <code>false</code>: </p>
  
  <pre><code>public class RegexFoo {
  
      public static void main(String[] args) {
          String regex = "\\b(https?|ftp|file)://[-A-Z0-9+&amp;@#/%?=~_|!:,.;]*[-A-Z0-9+&amp;@#/%=~_|]";
          String text = "http://google.com";
          System.out.println(IsMatch(text,regex));
  }
  
      private static boolean IsMatch(String s, String pattern) {
          try {
              Pattern patt = Pattern.compile(pattern);
              Matcher matcher = patt.matcher(s);
              return matcher.matches();
          } catch (RuntimeException e) {
          return false;
      }       
  }   
  }
  </code></pre>
  
  <p>Does anyone know what I am doing wrong?</p>