 <p>You may try this regex:</p> <pre><code>/^http(s?)://((\w+\.)?\w+\.\w+|((2[0-5]{2}|1[0-9]{2}|[0-9]{1,2})\.){3}(2[0-5]{2}|1[0-9]{2}|[0-9]{1,2}))(/)?$/gm </code></pre> <p>It's a bit lengthy but it works both with abc.domain.com, domain.com and valid IP addresses. You can test it <a href="http://regexr.com?329bj" rel="nofollow">here</a>.</p> <p>It's split into a "text" part, <code>(\w+\.)?\w+\.\w+</code> that matches any text without spaces and with one or two dots in it, and a numeric part, <code>((2[0-5]{2}|1[0-9]{2}|[0-9]{1,2})\.){3}(2[0-5]{2}|1[0-9]{2}|[0-9]{1,2})</code> allowing four numbers between 0 and 255 separated by dots.</p> <p>Optionally, there can be a slash at the end.</p> <p>If you don't mean to allow domains composed by single characters (eg. a.b.c) but, say, at least like www.bit.ly (that is, with free prefix of 1 or more characters, "body" of three or more, and suffix of two or more), you can change the text part into:</p> <pre><code>(\w+\.)?\w{3,}\.\w{2,} </code></pre> <p>Reference: </p> <p><a href="http://RegExr.com?2ri07" rel="nofollow">http://RegExr.com?2ri07</a> (regex matching ip)</p>