user492888
user492888

Reputation: 207

How to extract the URL from the string in java?

How to extract the URL from the below string. I searched in web for regex but it extracts only if http:// or www. How to extract for both the type of inputs?

Regex:
http://blog.houen.net/java-get-url-from-string/

Case1:

bhjhrwww.rrjhttp://www.google.com

Result:

http://www.google.com

Case2:

bhjhrwww.rrwww.google.com

Result:

www.google.com

Upvotes: 0

Views: 230

Answers (1)

vks
vks

Reputation: 67968

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

Try this.See demo.

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

Upvotes: 1

Related Questions