How to extract the URL from the string in java?
如何从以下字符串中提取URL。我在网上搜索了正则表达式,但仅在http://或www时才提取。如何为两种输入类型提取?
正则表达式:
http://blog.houen.net/java-get-url-from-string/
案例1:
1 | bhjhrwww.rrjhttp://www.google.com |
结果:
1 | http://www.google.com |
案例2:
1 | bhjhrwww.rrwww.google.com |
结果:
1 | www.google.com |
1 | \\\\(?(http://(?!.*http)|www[.](?!.*www))[-A-Za-z0-9+&@#/%?=~_()|!:,.;]+[.][-A-Za-z0-9+&@#/%=~_()|]*\\b |
尝试一下。请参阅演示。
https://regex101.com/r/nL5yL3/24