I am wondering what is the fastest, most efficient way (using JAVA) to search a large string and do a find replace such as:
find
'http://www.stackoverflow.com'
within the body of a long string and replace it with
'<a href="http://www.stackoverflow.com">http://www.stackoverflow.com</a>'
Now, before you suggest using XSL to do this it is already out of the question.
In a nut shell I would like to know how to find any instance of a URL within a long string and wrap it with the appropriate element so when the page renders on the web it will auto link. Thanks.
Regular expressions to the rescue! Look at this question Regular expression to match URLs in Java
Just use the find and replace from Matcher instaed of just finding it as in the previous question.
For completeness sake here is some code that does what you want.
NOTE: Assuming you have an anchor tag with a URL already in the string being replaced, you cannot use REGEX and must parse the text as HTML and only look at text nodes before you run the regex replace.