Questions tagged «regexbuddy»

8
正则表达式以匹配Java中的URL
在使用正则表达式时,我使用RegexBuddy。我从其库中复制了正则表达式以匹配URL。我在RegexBuddy中成功测试。但是,当我将其复制为JavaString样式并将其粘贴到Java代码中时,它将无法正常工作。以下类打印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; } } …
86 java  regex  regexbuddy 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.