开发者

Regex to match links that arent already marked up

开发者 https://www.devze.com 2022-12-09 19:33 出处:网络
I want to match any URL that isn\'t already enclosed in an href.i.e I want to ignore the following. <a href=\"http://www.test.com/whatever\">

I want to match any URL that isn't already enclosed in an href. i.e I want to ignore the following.

<a href="http://www.test.com/whatever">

I'm trying to write a regex to automatically find urls, so that I can turn them into marked up a hrefs.

The issue I'm having is dealing with urls that have already开发者_运维问答 been marked up (The documents contain a mix of marked up and not marked up urls).


Use negative look ahead to see if an url does NOT have </a> ahead of it

your_regex(?!\s*</a>)
0

精彩评论

暂无评论...
验证码 换一张
取 消