Ask for a regular, get the address of the image src

Source: Internet
Author: User




Regular takes the value of SRC in the above code
Image/ad1.gif
Image/ad2.gif
Image/ad3.gif
Image/ad4.gif
Image/ad5.gif

Reply content:





Regular takes the value of SRC in the above code
Image/ad1.gif
Image/ad2.gif
Image/ad3.gif
Image/ad4.gif
Image/ad5.gif

Get src value str, then Str.match (/image (s*) gif/) [0]

$('img').each(function(index,item){    console.log(item.src.match(/image(\S*)gif/)[0]);})

/src=(?:pattern'|\"|\\\['"]|\\\)?(.*?)(?:pattern'|\"|\\\['"]|\\\)?\sw/

I don't know, it's not right.

//如果你的src中肯定不包含空格的话可以用这个简单的办法,通常是ok的preg_match_all('/

这样得到的内容会包含单引号什么的,对于带有反斜线的单双引号先去掉反斜线,然后trim一下就行了,例如

foreach($_match[1] as str) { $str = str_replace("\\'", "'", $str); $str = str_replace('\\"', '"', $str); echo trim($str, '\'"');}

大致这样,具体的自己调试吧。不太复杂的正则匹配优先考虑关键字符来排除结果,比如本例中的空格及制表符。

http://tool.oschina.net/regex/

 ]*?src=\\? ["]? (.*?) ["]?\S[^>]*?>  

There should be a red envelope here

  $rule = ' # # ';  

You can try it: online regular expression generation tool

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.