Hakmor
V2EX  ›  问与答

如何用 python 正则匹配相应的内容呢?

  •  
  •   Hakmor · Sep 9, 2015 · 2677 views
    This topic created in 4072 days ago, the information mentioned may be changed or developed.

    一个文本,可能是这样的形式:

    内网-10.0.0.0 外网-182.0.0.0
    外网-123.2.2.2 内网-10.2.2.2
    内网-10.3.4.5
    外网-182.1.1.1
    
    内网-10.0.1.1 外网-182.0.1.1
    

    请问怎么用正则匹配出内网后的 ip 地址呢?

    4 replies  •  2015-09-10 10:09:11 +08:00
    imn1
    imn1
    Sep 9, 2015
    1
    ^[^\d\.]+([\d\.]+)
    gongpeione
    gongpeione
    Sep 9, 2015
    2
    import rem =
    text = "内网-10.0.0.1"
    m = re.findall (r"内网-(10\.(\d{1,3}\.){2}\d{1,3})", text )
    gongpeione
    gongpeione
    Sep 9, 2015❤️1
    3
    import re
    text = "内网-10.0.0.1 ·····"
    m = re.findall (r"内网-(10\.(\d{1,3}\.){2}\d{1,3})", text )

    手滑
    Hakmor
    Hakmor
    OP
    Sep 10, 2015
    4
    似乎输出格式还是不对

    我得到的是这样一个输出

    [('10.77.129.52', '129.')]

    text = "YY14072011 内网-10.77.129.52;管理卡-10.127.176.52;"
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1929 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 00:03 · PVG 08:03 · LAX 16:03 · JFK 19:03
    ♥ Do have faith in what you're doing.