Bookin Bookin - 9 months ago 26
Javascript Question

Get tag if src have value

I use this:

/\<img[\s\S]*url.com[\s\S]*?\/>/g


So I need remove img, if src have special url, but problem with html like this:

<img src="pofig.com/adfg"/>
<p>Text text text</p>
<img src="url.com/asfsdf/sdf"/>


Will be remove all tags, but I need only last img tag.

Example - https://regex101.com/r/4qjF0g/1

Answer Source

Instead of using [\s\S] which means anything you can use [^>]:

\<img[^>]*url.com[\s\S]*?\/>

See it live