Page 1 of 1

simple regex matching too much! :(

Posted: Wed Oct 26, 2005 3:45 pm
by cs-web
Hi I made this simple regex pattern to match URLs so I can convert them to links.

Code: Select all

(http://[0-9a-z/\.?_&-=;+])+
But when I put it to work on this text
Copy and paste this link, its a 40 minute Concert,<br />
<br />
http://www2.xfm.co.uk/staticweb/avplaye ... layhigh<br />
<br />
its pure <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> rock!<br />
It matches
I dont see how its matching the <br on the end?? If anybody can helf it would be brilliant.

Chris

Posted: Wed Oct 26, 2005 4:11 pm
by programmermatt
This works for me:

Code: Select all

(http:\/\/[0-9a-z\/\.?_&-=;]+)<
Though I would personally:

Code: Select all

http:\/\/(.*?)<

Posted: Wed Oct 26, 2005 4:23 pm
by cs-web
you suggestion wont match the URL in
and matches
in the original text and so still matches "<" at the end.

Posted: Wed Oct 26, 2005 11:29 pm
by shoebappa
What about:

Code: Select all

http:\/\/[0-9a-z\/\.\?_&\-=;\+]+
I may have escaped too much, but I think your problem is escaping things...

Or:

Code: Select all

http:\/\/[^\s<]+