1

I need to check if there are any http link in a string, but I don't figure it out yet how to do this. I know I can check if a link is a valid http link with something like the following

boolean valid = myString.matches("^(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");

I see it in this post here, it works if the string is just the link, without spaces and other words, but I want a regex to check for http links in a sentence, which could or not contains spaces and more words, I tried the next:

boolean valid = s.matches(".*\\s+^(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|].*$")

But I don't get it, I don' really know much about regex, so I'd appreciate any help.

Thankz in advance.

Community
  • 1
  • 1
J0t4
  • 38
  • 7
  • possible duplicate of [RegEx match open tags except XHTML self-contained tags](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Tdorno Jan 18 '14 at 03:09
  • No, not really, the regex is quite different, I don't want to extract any html tag links in source coder, rather http links in any sentence in plain text, quite diffetent. – J0t4 Jan 18 '14 at 03:23

1 Answers1

1
.*(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|].*$

Translated: (Any characters) hyperlink (Any characters)

You can test it here with some strings of your own.

Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130