Regex to match "www" or nothing
I have the following URLs:
www.localho开发者_运维技巧st.com
localhost.com
test.localhost.com
How would I match "www" or nothing in a Regex?
(?:www)?
should match www or nothing.
/^www/
alows you to check if subjects starts with www
.
If I understand your question correctly, you need to use a lookahead, like this:
/^www(?=\.localhost.com)/
This will match www
if and only if it's followed by .localhost.com
.
If that's not what you're trying to do, please clarify.
www.+? It matches all string that has prefix as www
精彩评论