hello,
i am looking for a snippet that parses an url out of a string.
for example in the string:
“Please visit www.java-gaming.org/blabla now”
should detect that www.java-gaming.org/blabla is an url. thanks!
hello,
i am looking for a snippet that parses an url out of a string.
for example in the string:
“Please visit www.java-gaming.org/blabla now”
should detect that www.java-gaming.org/blabla is an url. thanks!
i dont think: www.java-gaming.org/blabla is a url - its missing a protocol.
http://www.ietf.org/rfc/rfc1738.txt defines the url syntax, if you just want a quick solution though you can probably find a regex to do exactly what want.
Some simple solutions:
Use regular expressions. See Formatter class in the javadoc for examples and explanation.
Use the string.find method to search for keywords like http:// or www… You will get the index of that keyword in the string. From there search for the next whitespace and you’re done.
I’d suggest you try and if you need further help post your code here 
thanks, i was actually looking for the regex that does the job for me. 
i want to use it for a chat, where urls that are typed by users are clickable and open the url in a browser similar to irc.
for a simple chat you might get away with
([^\s]+\.[^\s]+)
if you don’t want to match java classes as urls, add a protocol requirement:
([^\s]+:[^\s]+\.[^\s]+)