kat But there are" /> kat But there are" /> kat But there are"/>

How to exclude an HTML tag in regex search

281 Views Asked by At

I'm using powerGrep to find instances of these:

BLOCK 1:

<td class="danish">kat
<?php audioButton("../../audio/words/dog","dog");?></td>

But there are also instances of these among my files:

BLOCK 2

<td class="danish">kat</td>
<td><?php audioButton("../../audio/words/dog","dog");?></td>

I want to find BLOCK 1 only, not BLOCK 2.

I've tried using (?!), as in

.*<td class(.*?)>(.*)(?!</td>)
.*<\?php audioButton\("(.*)/.*",".*"\);.*\?></td> 

Can I somehow exclude the </td> tag from the search, so that BLOCK 2 is ignored?

1

There are 1 best solutions below

3
antoni On BEST ANSWER

I am not sure why you really want to match the first cell tag only, but to perform this you can try:

<td[^>]*>\s*(?:.(?!</td>))+\s*<\?php audioButton\("[^"]*/(.+?)","(.*?)"\);.*?\?>.*?</td> with g flag.

see it working here: https://regex101.com/r/tI4rL4/1

[EDIT]

You can also see the replacement of dog to cat here: https://regex101.com/r/tI4rL4/2

It may not be perfect, since the question is a bit too vague, but it works. If you need to refine a bit or adjust or need a bit of explanation you can ask me!