开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜