How to convert a .Net regular expression to php -
i have regular expression used replace phrase if phrase not contained html anchor tags or img tag. example phrase being searched "hello world"
the .net regular expression
(?<!<a [^<]+)(?<!<img [^<]+)(?<=[ ,.;!]+)hello world(?=[ ,.;&!]+)(?!!.*</a>)
e.g. regular expression should match "hello world" in phrase
"one 2 3 hello world 4 five"
but shouldn't match hello world in phrase like
"one 2 3 <a href='index.html'> hello world </a> 4 five"
or
"one 2 3 <img alt='hello world' \>four five"
it associated following question when developing .net version. regular expression doesn't match string if it's text within html anchor tag
any guidance on how go converting php regex appreciated.
note: not use regular expression parse tags.
for a
or img
tags specifically, following.
(?!<(?:a|img)[^>]*?>)\bhello world\b(?![^<]*?(?:</a>|>))
see live demo
i suppose in or between tags, try this.
(?!<[^>]*?>)\bhello world\b(?![^<]*?(?:</[^/]*>|>))
see live demo
Comments
Post a Comment