a13327022
2018-12-21 14:48
采纳率: 71.4%
浏览 2.5k

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());
        }
    
    }
    
    
    点赞 评论
  • dabocaiqq 2018-12-21 15:49
    点赞 评论

相关推荐 更多相似问题