开发者

Regex to match "www" or nothing

开发者 https://www.devze.com 2022-12-15 19:54 出处:网络
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)?

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

精彩评论

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

关注公众号