zddewe
V2EX  ›  问与答

讨教正则表达式

  •  
  •   zddewe · Nov 16, 2017 · 1562 views
    This topic created in 3172 days ago, the information mentioned may be changed or developed.
    5 replies    2017-11-16 13:00:08 +08:00
    Carseason
        1
    Carseason  
       Nov 16, 2017 via iPhone
    分割或者替换
    oott123
        2
    oott123  
       Nov 16, 2017
    ^https://www\.google\.[a-z.]+/
    boboliu
        3
    boboliu  
       Nov 16, 2017 via Android
    split 一把梭完事,要什么正则。。。

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

    最后,https://u.bobiji.com/tiwen
    freedomSky
        4
    freedomSky  
       Nov 16, 2017
    只会 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  
       Nov 16, 2017
    function (str) {
    return str.replace(/https:\/\/www\.google\.(.*?)\//g, 'https://www.google.com/')
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2644 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 12:48 · PVG 20:48 · LAX 05:48 · JFK 08:48
    ♥ Do have faith in what you're doing.