0

I'm using this regex which so far has been pretty good...

var r = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;

But if I have a string such as the following...

 '<div>http://www.a-random-site.com/page1-blah-blah</div>Another bit of text'

Then the bit that is matched would be...

http://www.a-random-site.com/page1-blah-blah</div>Another

How can I alter the regex to take into account that an angled bracked could terminate a link?

0

2 Answers 2

1

I edited saram's regex pattern and tested it by Expresso and it worked with your sample :

(?:http|ftp|https):\/\/[\w\-_]+(?:\.[\w\-_]+)+(?:[\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?
Sign up to request clarification or add additional context in comments.

Comments

0

I do not know if there is easy way to fix your regexp. I just use this code for url:

(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?

Source link

Working example

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.