Creating java regex to get href link

我是研究僧i 提交于 2019-11-30 10:58:11

You do not have to use replaceAll. Better use pattern groups like the following:

Pattern p = Pattern.compile("href=\"(.*?)\"");
Matcher m = p.matcher(html);
String url = null;
if (m.find()) {
    url = m.group(1); // this variable should contain the link URL
}

If you have several links into your HTML perform m.find() in loop.

If you always have one such link in a string, try this:

"(^[^\"]*\")|(\"[^\"]*)$"

you can checkout http://regexlib.com/ for all the regex help you need. And the one below is for url :

^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!