Reputation: 272296
I want a regular expression that matches the following
example.com -> matches, returns example.com
foo-bar.com -> matches, returns foo-bar.com
www.example.com -> does not match
www.foo-bar.com -> does not match
Easy? I just need the PERL compatible regular expression that tests if the string does not begin with www.
, and if so, captures and returns the whole string.
Upvotes: 3
Views: 72
Reputation: 50928
You should be able to use this:
/^(?!www\.)(.*)$/
Explanation:
^
and $
anchor the match, so it has to match the entire string given.(?!www\.)
is a negative lookahead, which blocks the match if the string starts with www.
.(.*)
captures the entirety of the string.Upvotes: 4