讨教正则表达式

2017-11-16 12:08:09 +08:00
 zddewe

请教大佬一个正则

https://www.google.co.kr/beijing https://www.google.cn/beijing https://www.google.com.hk/beijing

我想把他们都转换成 https://www.google.com/beijing,咋整

1046 次点击
所在节点    问与答
5 条回复
Carseason
2017-11-16 12:28:24 +08:00
分割或者替换
oott123
2017-11-16 12:36:25 +08:00
^https://www\.google\.[a-z.]+/
boboliu
2017-11-16 12:38:37 +08:00
split 一把梭完事,要什么正则。。。

btw,正则也很好写,老哥咱能不能自学一下。。。

最后,https://u.bobiji.com/tiwen
freedomSky
2017-11-16 12:38:48 +08:00
只会 sed 版,

sed 's/https:\/\/www.google.[^/]*\/beijing/https:\/\/www.google.com\/beijing/'


case1:
echo "123 https://www.google.co.kr/beijing 456" | sed 's/https:\/\/www.google.[^/]*\/beijing/https:\/\/www.google.com\/beijing/' -

case2:
echo "123 https://www.google.co.kr/abeijing 456" | sed 's/https:\/\/www.google.[^/]*\/beijing/https:\/\/www.google.com\/beijing/' -
hapboy
2017-11-16 13:00:08 +08:00
function (str) {
return str.replace(/https:\/\/www\.google\.(.*?)\//g, 'https://www.google.com/')
}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/406890

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX