B
Bryan Kennerley
I'm putting together a web forum and want to parse web addresses that
are part of messages into clickable links. This is my attempt, I'm not
claiming its perfect but it works:
text.gsub!(/http:?\/*(\w+[\w\-\.\/~\?%&=#;,\+:\@]+)/,
' <a href="http://\1" target="_blank">http://\1</a>')
The problem is that some web addresses are incredibly long, so I want
the link text to be limited to, say, 50 chars. i.e. the second \1 needs
to be \1[0..49] or something. I can't figure out any easy way of doing
it, any ideas?
are part of messages into clickable links. This is my attempt, I'm not
claiming its perfect but it works:
text.gsub!(/http:?\/*(\w+[\w\-\.\/~\?%&=#;,\+:\@]+)/,
' <a href="http://\1" target="_blank">http://\1</a>')
The problem is that some web addresses are incredibly long, so I want
the link text to be limited to, say, 50 chars. i.e. the second \1 needs
to be \1[0..49] or something. I can't figure out any easy way of doing
it, any ideas?