I use RegexBuddy while working with regular expressions. From its library i copied the regular expression to match urls. I tested succesfully within regexbuddy. However, when I copied it as Javas String flavor and pasted it into java code it does not work. The next class prints false:
public class RegexFoo {
public static void main(String[] args) {
String regex = "\\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]";
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;
}
}
}
Does anyone what i am doing wrong?