I have a JS regex to replace sections of a string that include img tags inside p tags. I'm picking up ones I don't want.
Sample of what I want to find and replace (the src and class are not always in the same order and imageData is not always the same base64 "numbers", so I can't just match on the whole string):
<p><img class="classIWantToMatch" src="data:image/gif;base64,dataForImage"></p>
<p><img src="data:image/gif;base64,imageData" class="classIWantToMatch" ></p>
Sample that is also getting found and replaced (but I don't want to):
<p><img src="/myFiles/my.PNG" alt=""></p>
Regex:
/(<p><img).*?(class="classIWantToMatch").*?(<\/p>)/g
I'm trying to figure out lookahead and lookbehind, but I can't seem to make it do what I want.
Besides ye olde basic googling, I tried here:
A Regex that search for lines that contains a string, and not contains another string
Using Regex to find string that contains one string and excludes a second string?
and several other ones as well. I think I just don't understand lookahead/behind.
Some text
- Entrances increased 6% from 5,681 to 6,009
- Some text
![]()
– Jeff May 03 '19 at 17:12Some Text
Some Text