问题描述

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

预期行为:

http://example.com - Match
http://www.example.com - Does not match
 golang  golang 
golanggolang

更新

我不是使用golang进行编码,而是使用 Traefik 接受正则表达式(golang风格)作为配置值,所以基本上我有这个:

I'm not coding using golang, I'm using Traefik that accepts a Regex (golang flavor) as a config value, so basically I have this:

regex = "^https://(.*)$"
replacement = "https://www.$1"

我想要的是始终在URL中添加 www.,但是如果该URL已经包含 NOT ,则为 NOT ,否则它将成为 www.www.*

What I want is to always add www. to the URL, but NOT if the URL has it already, otherwise it would become www.www.*

推荐答案

 w 
w
^https?://(([^w].+|w(|[^w].*)|ww(|[^w].+)|www.+)\.)?example\.com$
 example.com  www  w  w  w  w  w  w  www 
example.comwwwwwwwwwwww
 www.
www.

搜索:

^http://(?:www\.)?(.*)\b$

替换:

http://www.$1

这篇关于正则表达式匹配golang中不以www开头的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!