regexstring

Very simple regular expression question regarding "assertions"


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.


Solution

  • You should be able to use this:

     /^(?!www\.)(.*)$/
    

    Explanation: