Extracting URLs from a text document using Java + Regular Expressions

后端 未结 4 1569
醉话见心
醉话见心 2020-12-08 23:11

I\'m trying to create a regular expression to extract URLs from text documents using Java, but thus far I\'ve been unsuccessful. The two cases I\'m looking to capture are li

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 23:26

    This tests a certain line if it is a URL

    Pattern p = Pattern.compile("http://.*|www\\..*");
    Matcher m = p.matcher("http://..."); // put here the line you want to check
    if(m.matches()){
        so something
    }
    

提交回复
热议问题