Removing the url from text using java

前端 未结 7 1825
梦毁少年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条回答
  •  无人及你
    2020-12-15 08:24

    How do you define URL? You might not just want to filter http:// but also https:// and other protocols like ftp://, rss:// or custom protocols.

    Maybe this regular expression would do the job:

    [\S]+://[\S]+

    Explanation:

    • one or more non-whitespaces
    • followed by the string "://"
    • followed by one or more non-whitespaces

提交回复
热议问题