I am looking for a RegEx that will match a complete tag of an unknown length where a given keyword is within the tag. So when I am looking for the string "example" I want to match the whole tag:
<a href="https://www.justsomestuff.com/andevenmorestuffnotof interest" target="_new" and so on>example</a>
example
As I have no understanding for RegEx at all, I didn’t know how to start at all.
2
Answers
I recommend finding introductory material on regex and having a read through. This will greatly help you understand and implement the solution you need. WordPress is implemented in PHP, so you will likely want to find materials regarding PCRE, which is a regex implementation commonly used with PHP.
To match your example, I would consider this regex:
Know that processing HTML with regex is not often advised because HTML can be more complicated than regex can handle. You may wish to consider HTML parsers instead.
You can try this example:
Here is a little test: https://regex101.com/r/eBj9tj/1
Or you can test it in PHP: