Reputation: 315
I have this RegEx expression to match http:// links-like part of text:
([A-Za-z]{3,9}):\/\/([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?(\/[-\+~%\/\.\w]+)?\??([-\+=&;%@\.\w]+)?#?([\w]+)?
and later convert them to hyperlinks with some code. It really works good.
However, http:// part of text can be found in < img > tag too:
<img src="http://www.nature.com/images/home_03/main_news_pic2013.02.19.jpg" alt="Pulpit rock" width="304" height="228">
So, I have to modify existing RegEx to NOT match http links-like part of text with quotation mark or apostrophe before. How to NOT match:
"http
I tried with [^"|']:
[^"|']([A-Za-z]{3,9}):\/\/ ..........
but it does not work.
Upvotes: 0
Views: 148
Reputation: 109100
You need to use a negative lookbehind (ie. "not preceded by"):
(?<!")http://…
Upvotes: 2