I am trying to extract text using preg_match()
which is not contained in tags like <p>
or <img>
. This text is retrieved from a database and I am working in PHP.
This should be extracted <p>I do not want this</p> This should be extracted <a>This may appear after other tags and I do not want this</a>
I have tried to do (.*)(<p>|<a>|<\/p>|<\/a>)(.*)
but this will capture everything up till the last tag and the earlier tags are captured together with text outside of tags.
I have tried to search on Stackoverflow like this: Match text outside of html tags but the regex provided has a pattern error when I pasted it in regex101.com.
Would appreciate any help on this, thanks.