There are three issues with your attempt: boundaries of your matches, using '.*' and missing pattern for legal postfix.
The dot star notation is a bad idea in RegEx, which the article "Death to Dot Star!" illustrates quite well. Use negated character classes instead, and here I chose "\S*?" which is "any character that is not a whitespace". If you try replacing that with ".*?" instead on regex101, you can see it failing to match properly (it includes a link that is not an image).
Since it is all in the same string, boundries must be defined for the match, and since whitespace is sufficient "\b" does the trick nicely. This also removes the need for the "(.*)" and "(\w|$)" parts.
The last thing you missed was the legal endings to the url, and there are two solutions to this: Either define what you think is plausible to include most scenarios and have no false positives, or include anything but have a chance of getting too many results.
Wrap it all together, and you are left with these two different approaches:
(\/\/[^"']*\.(?:png|jpg|jpeg|gif|png|svg))
String text to test
<div data-src="//img.alicdn.com/imgextra/i4/O1CN01r3WpYb1re2NNIrDMi_!!0-rate.jpg" class="pic" style="background-image: url(//img.alicdn.com/imgextra/i4/O1CN01r3WpYb1re2NNIrDMi_!!0-rate.jpg);" data-spm-anchor-id="a261y.7663282.autotrace-offerDetailContext3.i0.19c041749nQhXC"></div>
Nhận xét
Đăng nhận xét