Q
questionmarc420
hi again,
i have large strings containing many paragraphs. The string is to be
displayed. I want to have all substrings that start with "html" and
"www." wraped in <a></a> tags.
here is the code i have:
data_body = data_body.replaceAll("((https?|ftp)://|mailto[^\\s<]+",
"<A TARGET=\"_new\" HREF=\"$0\">$0</a>");
data_body = data_body.replaceAll("(www.)[^\\s<]+", "<A
TARGET=\"_new\" HREF=\"http://$0\">$0</a>");
my problem is:
if a link is "http://www." the substring is replaced twice. meaning the
link would appear something like this:
< a HREF=http://<a HREFwww.>http://www.</a/a>>
or soemthing along those lines.
i tried putting the www. in the first expression but that does not work
because it only links to the locahost.
i also tried adding a space before the "www." so it would be like "
www."
this almost worked however there came to be spaces in the link so it
would not work in the browser.
if anyone understands and can help, please do.
if you are unclear on anything praticualr please tell me to explain.
thanks
-morc
oh and also sometimes if a link is placed in parentheses in the text
then it tends to add them to the link. if anyone knows of a way to
exclude the parentheses please share. thanks
i have large strings containing many paragraphs. The string is to be
displayed. I want to have all substrings that start with "html" and
"www." wraped in <a></a> tags.
here is the code i have:
data_body = data_body.replaceAll("((https?|ftp)://|mailto[^\\s<]+",
"<A TARGET=\"_new\" HREF=\"$0\">$0</a>");
data_body = data_body.replaceAll("(www.)[^\\s<]+", "<A
TARGET=\"_new\" HREF=\"http://$0\">$0</a>");
my problem is:
if a link is "http://www." the substring is replaced twice. meaning the
link would appear something like this:
< a HREF=http://<a HREFwww.>http://www.</a/a>>
or soemthing along those lines.
i tried putting the www. in the first expression but that does not work
because it only links to the locahost.
i also tried adding a space before the "www." so it would be like "
www."
this almost worked however there came to be spaces in the link so it
would not work in the browser.
if anyone understands and can help, please do.
if you are unclear on anything praticualr please tell me to explain.
thanks
-morc
oh and also sometimes if a link is placed in parentheses in the text
then it tends to add them to the link. if anyone knows of a way to
exclude the parentheses please share. thanks