Division has a business need to match the URL in the text, the degree Niang, gu elder brother a half-day often see have to get hyperlinks in HTML, as long as the matching <a href=[' "]? (.*?) [']? Yes, but if it's an ordinary text type, it's a bit more cumbersome to share the final expression:
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern; public class Urlmatcher {public static void main (string[] args) {Pattern pattern = pattern. Compile ("Http://|ftp ://|https://|www) {0,1}[^\u4e00-\u9fa5\\s]*?\\. (COM|NET|CN|ME|TW|FR)
[^\u4e00-\u9fa5\\s]* ");
Space end Matcher Matcher = pattern. Matcher ("Download address http://www.zuidaima.com/sdfsdf.htm?aaaa=%ee%sss? sdfsyyy space End");
while (Matcher.find ()) {System.out.println (Matcher.group (0));
///Chinese end matcher = pattern. Matcher ("Download address http://www.zuidaima.com/sdfsdf.htm?aaaa=%ee%sss URL end");
while (Matcher.find ()) {System.out.println (Matcher.group (0));
///no http://opening matcher = pattern. Matcher ("Download address www.zuidaima.com/sdfsdf.htm?aaaa=%ee%sss URL end");
while (Matcher.find ()) {System.out.println (Matcher.group (0));
//NET domain name Matcher = pattern. Matcher ("Download address www.xxx.net/sdfsdf.htm?aaaa=%ee%sss URL end");
while (Matcher.find ()) {System.out.println (Matcher.group (0)); //XXX domain name Matcher = pattern. Matcher ("Download address www.zuidaima.xxx/sdfsdf.htm?aaaa=%ee%sss URL end");
while (Matcher.find ()) {System.out.println (Matcher.group (0));
The//YYYY domain name does not match the System.out.println ("not match yyyy domain name");
Matcher = pattern. Matcher ("Download address www.zuidaima.yyyy/sdfsdf.html?aaaa=%ee%sss URL end");
while (Matcher.find ()) {System.out.println (Matcher.group (0));
//No http://www.
Matcher = pattern. Matcher ("Download address zuidaima.com/sdfsdf.html?aaaa=%ee%sss URL end");
while (Matcher.find ()) {System.out.println (Matcher.group (0)); }
}
}
The result is dead, but the idea is alive, everyone can rewrite the expression according to their own business.
There is a picture of the truth:
Related code Download: http://www.zuidaima.com/share/1575653789993984.htm reprint please indicate the source.