D
David Krmpotic
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, '<a
href=\'\0\'>\0</a>')
link becomes:
link = "Go here: <a
href='http://www.something.com'>http://www.something.com</a>!"
Now...
When the link is this:
link = "Go here: <a
href='http://www.something.com'>http://www.something.com</a>!"
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, '<a
href=\'\1\'>\1</a>')
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
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, '<a
href=\'\0\'>\0</a>')
link becomes:
link = "Go here: <a
href='http://www.something.com'>http://www.something.com</a>!"
Now...
When the link is this:
link = "Go here: <a
href='http://www.something.com'>http://www.something.com</a>!"
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, '<a
href=\'\1\'>\1</a>')
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