V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
zddewe
V2EX  ›  问与答

讨教正则表达式

  •  
  •   zddewe · 2017-11-16 12:08:09 +08:00 · 1043 次点击
    这是一个创建于 2346 天前的主题,其中的信息可能已经有所发展或是发生改变。
    5 条回复    2017-11-16 13:00:08 +08:00
    Carseason
        1
    Carseason  
       2017-11-16 12:28:24 +08:00 via iPhone
    分割或者替换
    oott123
        2
    oott123  
       2017-11-16 12:36:25 +08:00
    ^https://www\.google\.[a-z.]+/
    boboliu
        3
    boboliu  
       2017-11-16 12:38:37 +08:00 via Android
    split 一把梭完事,要什么正则。。。

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

    最后,https://u.bobiji.com/tiwen
    freedomSky
        4
    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
        5
    hapboy  
       2017-11-16 13:00:08 +08:00
    function (str) {
    return str.replace(/https:\/\/www\.google\.(.*?)\//g, 'https://www.google.com/')
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4948 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 05:38 · PVG 13:38 · LAX 22:38 · JFK 01:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.