Here’s the regular expression I use, and I parse it using CAtlRegExp of MFC :
(((h|H?)(t|T?)(t|T?)(p|P?)(s|S?))://)?([a-zA-Z0-9]+[\.]+[a-zA-Z0-9]+[\.]+[a-zA-Z0-9])
It works fine except with one flaw. When URL is preceded by characters, it still accepts it as a URL.
ex inputs:
-
this is a link http://www.google.com (where I can just tokenize the spaces and validate each word)
-
is…www.google.com (this string still matches the RegEx above 🙁 )
Please help…
Thanks…
You need to tell the regex to only match at the start and end of the string. I’m not sure how you do that in VC++ – in most regexs you enclose the pattern with
^and$. The^says “the start of the string” and the$says “the end of the string.”The second is matching because the string still contains a valid URL.