Reputation: 81
I'm using:
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(exp,"<a href='$1' target='internet'>$1</a>");
to turn, for example http://www.example.com
into a clickable link. This works well!
Does anyone know how to expand this expression to capture also www.example.com
(i.e without http://
)?
Upvotes: 3
Views: 226
Reputation: 34855
This worked for me:
Add a ( )*
here
((https?|ftp|file):\/\/)*
http://jsfiddle.net/jasongennaro/NBWyr/
Basically zero or more of the items in ()
Upvotes: 1
Reputation: 3986
try this regex:
(?<http>(http:[/][/]|www.)([a-z]|[A-Z]|[0-9]|[/.]|[~])*)
Upvotes: 0