Paul
Paul

Reputation: 9541

Regex to match all non http links, but not mailto

How can I alter this regex to not match mailto links?

(href|src)\=\"([^(http)])(\/)?

Regular expression visualization

Debuggex Demo

Should match

<a href="myurl">

Should not match

<a href="http://myurl">
<a href="mailto://myurl">

Upvotes: 2

Views: 1413

Answers (4)

Divya Bhaloidiya
Divya Bhaloidiya

Reputation: 5064

Use following one its working :

((mailto\:|(news|(ht|f)tp(s?))\://){1}\S+)

Here you can test it : http://regexlib.com/RETester.aspx?regexp_id=37

Upvotes: 0

netanelw
netanelw

Reputation: 121

As suggested, try using Negative-lookahead.

This could give you a head-start:

(href|src)\=\"(?!(http|mailto))(\/)?

Upvotes: 0

Paul
Paul

Reputation: 9541

Just in case someone else comes across this question, I changed it like this

(href|src)\=\"(?!http|mailto)(\/)?

Regular expression visualization

Debuggex Demo

Upvotes: 3

Duncan Smith
Duncan Smith

Reputation: 538

Use a negative lookahead to dismiss urls with mailto

http://www.regular-expressions.info/lookaround.html

Upvotes: 0

Related Questions