java用正则表达式提取background:url和background-image:url中的链接
<section style="padding: 10px 10px 30px; line-height: 30px; box-shadow: rgb(204, 204, 204) 2px 0px 10px; overflow: hidden; background-image: url(&quot;https://mpt.135editor.com/mmbiz_gif/uN1LIav7oJ84T6TnzapJHpqQx8IaOOL0nfYWuyCbx2G0xHn6fdnU2oSicxJ0ibuja6gdvdemx9AHdbB6VUo9zkWA/0?wx_fmt=gif&quot;); background-size: 100%; box-sizing: border-box;" class="135bg">
<section style="background: url(http://image2.135editor.com/cache/remote/aHR0cHM6Ly9tbWJpei5xbG9nby5jbi9tbWJpel9wbmcvN1FSVHZrSzJxQzQ4UUZIaDNWaWJZMUtRNUpaR2haNlR3dzBtV2ljQnNtcHR2cWY3MU1nYUJYaG5JdzQ3R3doRmp2VXJqZU55MnBwM0hnM3RQQ3JIREQ1Zy8wP3d4X2ZtdD1wbmc=)repeat-x;background-size:40px 4px;background-position:top ;">

用正则表达式取出
https://mpt.135editor.com/mmbiz_gif/uN1LIav7oJ84T6TnzapJHpqQx8IaOOL0nfYWuyCbx2G0xHn6fdnU2oSicxJ0ibuja6gdvdemx9AHdbB6VUo9zkWA/0?wx_fmt=gif

http://image2.135editor.com/cache/remote/aHR0cHM6Ly9tbWJpei5xbG9nby5jbi9tbWJpel9wbmcvN1FSVHZrSzJxQzQ4UUZIaDNWaWJZMUtRNUpaR2haNlR3dzBtV2ljQnNtcHR2cWY3MU1nYUJYaG5JdzQ3R3doRmp2VXJqZU55MnBwM0hnM3RQQ3JIREQ1Zy8wP3d4X2ZtdD1wbmc=

正则表达式应该怎么写

2个回答

1.

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexMatches {

    public static void main(String args[]) {
        String str = "";
        String pattern = ""((ht|f)tps?):\\/\\/(.*?)&quot";

        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(str);
        System.out.println(m.matches());
    }

}

2.

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexMatches {

    public static void main(String args[]) {
        String str = "";
        String pattern = "\\(((ht|f)tps?):\\/\\/(.*?)\\)";

        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(str);
        System.out.println(m.matches());
    }

}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问