简体   繁体   English

如何从java中的字符串中提取URL?

[英]How to extract the URL from the string in java?

How to extract the URL from the below string. 如何从下面的字符串中提取URL。 I searched in web for regex but it extracts only if http:// or www. 我在网上搜索了正则表达式,但仅在http://或www时才提取。 How to extract for both the type of inputs? 如何为两种输入类型提取?

Regex : 正则表达式
http://blog.houen.net/java-get-url-from-string/ http://blog.houen.net/java-get-url-from-string/

Case1 : 情况1

bhjhrwww.rrjhttp://www.google.com

Result: 结果:

http://www.google.com

Case2 : 情况二

bhjhrwww.rrwww.google.com

Result: 结果:

www.google.com
\\(?(http://(?!.*http)|www[.](?!.*www))[-A-Za-z0-9+&@#/%?=~_()|!:,.;]+[.][-A-Za-z0-9+&@#/%=~_()|]*\b

Try this.See demo. 试试看。看演示。

https://regex101.com/r/nL5yL3/24 https://regex101.com/r/nL5yL3/24

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM