a13327022 2018-12-21 14:48 采纳率: 0%
浏览 3005
已采纳

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条回答 默认 最新

  • lyhsdy 2018-12-22 03:46
    关注

    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());
        }
    
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 我这模型写的不对吗?为什么lingo解出来的下面影子价格这一溜少一个变量
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波