Creating java regex to get href link

后端 未结 3 1829
自闭症患者
自闭症患者 2021-01-01 07:33

Sorry if this has been asked before, but I couldn\'t find any answers on the web. I\'m having a hard time figuring out the inverse to this regex:

\"\

相关标签:
3条回答
  • 2021-01-01 07:53

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

    "(^[^\"]*\")|(\"[^\"]*)$"
    
    0 讨论(0)
  • 2021-01-01 08: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.

    0 讨论(0)
  • 2021-01-01 08:15

    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)$
    
    0 讨论(0)
提交回复
热议问题