From: David Krmpotic Date: 2007-02-06T05:37:45+09:00 Subject: Regular expressions (extracting urls) Hi! I have to extract an url from the text and make it a link (a href...).. The trick is that I have to be careful not to replace the url, that are already a part of the link. so: link = "Go here: http://www.something.com!" link.gsub!(/https?:\/\/[a-z0-9\.\-\_=&\+\/\?]+/i, '\0') link becomes: link = "Go here: http://www.something.com!" Now... When the link is this: link = "Go here: http://www.something.com!" The regular expression must not replace it! I know that for example if I want to exclude the links that start with xhttp, I can write: link.gsub!(/([^x]https?:\/\/[a-z0-9\.\-\_=&\+\/\?]+)/i, '\1') but how can I exclude links that start with href=" and href=' ? The problem is that I don't know how to specify that HREF cannot preceede the link (cannot write [^href], [^(href)] doesn't seem to work either and it also screws \n ... ) Please help ! David -- Posted via http://www.ruby-forum.com/.