a13327022
a13327022
采纳率71.4%
2018-12-21 14:48 阅读 2.3k

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

  • 已采纳
    weixin_39416561 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 评论 复制链接分享
  • dabocaiqq dabocaiqq 2018-12-21 15:49

相关推荐