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
Post a Comment