Regex to match "www" or nothing

regex

Solution

(?:www)?

should match www or nothing.

Problem

I have the following URLs: ``` www.localhost.com localhost.com test.localhost.com ``` How would I match "www" or nothing in a Regex?

Original source