Removing the url from text using java

前端 未结 7 1826
梦毁少年i
梦毁少年i 2020-12-15 07:59

How to remove the URLs present in text example

String str=\"Fear psychosis after #AssamRiots - http://www.google.com/LdEbWTgD http://www.yahoo.com/mksVZKBz\"         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 08:21

    Well, you haven't provided any info about your text, so with the assumption of your text looking like this: "Some text here http://www.example.com some text there", you can do this:

    String yourText = "blah-blah";
    String cleartext = yourText.replaceAll("http.*?\\s", " ");
    

    This will remove all sequences starting with "http" and up to the first space character.

    You should read the Javadoc on String class. It will make things clear for you.

提交回复
热议问题