java/jsp String manipulation problem

Q

questionmarc420

Hi,
i have large paragraphs in form of Strings. and i need to iterate
through it and change all links into hyperlinks
this is what i used to format the text into readable paragraphs.


String data_body = data.getBody();
data_body = data_body.replaceAll("\n\n","<p>");


now iw ould like to know if anyone knows of a way i can replace all
www.blablahs.com wiht working <A href>www.blahblahs.com</a>


thanks
morc
 
Q

questionmarc420

hey thanks this worked. another quick question though:
how would make the link open in a new window?

thanks again
morc
 
S

steen

hey thanks this worked. another quick question though:
how would make the link open in a new window?

thanks again
morc

Well the easy answer would be to simple extend the regular expression
like so:
str = str.replaceAll("((https?|ftp)://|mailto:)[^\\s<]+", "<A
TARGET=\"_new\" HREF=\"$0\">$0</a>");

/Steen
 
Q

questionmarc420

thanks eveyrthing worked.
but i ran into a little problem, i was wondering if anyone knew waht i
should do.

lets say the text is "(www.blahblah.com)"
the code will include the ")" at the end of the string. Anyone know a
way around this?

thanks
morc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top