maxduke
V2EX  ›  问与答

求解正则表达式

  •  
  •   maxduke · Oct 11, 2013 · 3290 views
    This topic created in 4770 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
    123123
    Oct 11, 2013
    1
    根据LZ的条件没看懂如何不匹配https://eee.ccc.com
    11
    11
    Oct 11, 2013❤️1
    2
    https?://\w+\.[^fff]+\.\w+\/[^\w]
    wenLiangcan
    wenLiangcan
    Oct 11, 2013❤️1
    3
    额,只会一点点 vim 的正则匹配

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

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