how can i match a text that is outside of an anchor tag ? example : "test <a>test</a>"
i want to get the test outside of the a tags only.
thanks.
how can i match a text that is outside of an anchor tag ? example : "test <a>test</a>"
i want to get the test outside of the a tags only.
thanks.
You're getting into dangerous land here in the sense that trying to parse HTML/XML with regular expressions is not feasible in most cases. Is parsing the markup not an option?
just read this.
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags
You need to use a look-ahead regex. These can be quite complex. See this page for more info about this topic: http://www.regular-expressions.info/refadv.html
For your simple example, something like this would do the trick:
/test(?=<a>test<\/a>)/
However, it will get very very complex if you need to match against more varied HTML, to the point that it may be virtually impossible to get right if you don't know how the input HTML will be formatted.
You may therefore find it better in the long run to use a DOM parser to locate text in an HTML document.