regex - java expression match -


i writing code replace expression follows

    scanner sc = new scanner(system.in);     string str = sc.nextline();      str=str.replaceall("http\\s+", "url ");  //used answer given     system.out.println(str); 

i giving input

icloud hits 20m users http://www.google.com/htputbfk via @cnet

and want output

english url english @cnet

but getting

icloud hits 20m users url @cnet.

after want modify

english url @cnet 

the modification changes parts of sentence not following special character(like #,%,@ etc.) english.

if want replace web address, regex can simpler:

http\\s+ 

and that's all!

it scans http , non spaces can find. stops @ first space.

to on safe side , avoid case of word starting http make regex bit longer , safer:

'http://\\s+' 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -