maxduke
V2EX  ›  问与答

求解正则表达式

  •  
  •   maxduke · Oct 11, 2013 · 2949 views
    This topic created in 4605 days ago, the information mentioned may be changed or developed.
    现在有很多location:
    http://aaa.ccc.com/
    https://eee.fff.com/ggg/
    https://eee.ccc.com/ggg/

    现在只想匹配第一集目录(带协议和域名的部分)的内容(第一个/前)且域名不为fff.com的条目。

    针对以上三条的匹配结果应该是:
    http://aaa.ccc.com
    不匹配
    https://eee.ccc.com

    求解这样的正则表达式怎么写
    5 replies    1970-01-01 08:00:00 +08:00
    123123
        1
    123123  
       Oct 11, 2013
    根据LZ的条件没看懂如何不匹配https://eee.ccc.com
    11
        2
    11  
       Oct 11, 2013   ❤️ 1
    https?://\w+\.[^fff]+\.\w+\/[^\w]
    wenLiangcan
        3
    wenLiangcan  
       Oct 11, 2013   ❤️ 1
    额,只会一点点 vim 的正则匹配

    先去除 https 的
    %s/^https.*$//g

    再去除 fff.com
    %s/^http*:\/\/..*.fff.com.*$//g
    ericls
        4
    ericls  
       Oct 11, 2013   ❤️ 1
    把内容按"/"切开更方便
    rrfeng
        5
    rrfeng  
       Oct 11, 2013   ❤️ 1
    grep -Po 'https?://[^/]*(?<!fff\.com)/'
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4103 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 04:14 · PVG 12:14 · LAX 21:14 · JFK 00:14
    ♥ Do have faith in what you're doing.