java - How to detect links in a text? -


greetings have text may contain links like:

" hello..... visit on http://www.google.com.eg, , more info, please contact on http://www.myweb.com/help"

and want find , replace link following link

anyone knows how ?

and have question how website stackoverflow detects links in posts 1 , highlights them 1 can click them , visit link?

using java.util.regex can urls finding matches regexp: https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\s+)?)?)?.

import java.util.regex.*;  pattern pattern = pattern.compile("https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\s+)?)?)?", pattern.case_insensitive | pattern.dotall | pattern.multiline); matcher mymatcher = pattern.matcher(mystringwithurls); while (mymatcher.find()) {     ... } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -