【问题标题】:Regex to extract fields正则表达式提取字段
【发布时间】:2017-08-23 21:23:09
【问题描述】:

我想从下面的示例事件中提取 URL 的某些部分并保存在从 http:// al 到 m3u8 的事件中捕获组 L_URL 中,问题是两个事件的格式不同

示例事件1

23 Aug 2017 19:04:38 [WARN ] http_srv: DONE 1259531 0.006744 404[Not Found] UNKNOWN-ID 69.132.62.224:22836 GET http://mmdai-linear-west-03.abc.com/linear-scope010.le.com/LIVE/1008/hls/ae/Nat_HD/.swn93bf20ea-8fb5-4493-9f5e-005056b23b1dapple2apple/.rate_3764512/index_v_3764512_7.m3u8?nw=376521&prof=376521:twc_hls_live&mode=live&vdur=600&caid=NGC_LIVE&csid=stva_android_ph_live&vcid=c4424608-d8cc-3f28-a171-c496b32e99a3&z5=28213&ads=VAST_LIVE&tagset_name=VAST&_fw_lpu=http://linear-scope010.le.com/LIVE/1008/hl... (id 5782790)

示例 2:

23 Aug 2017 19:04:38 [WARN ] http_srv: Total latency exceeded threshold: 0.053182 seconds (internal 0.053000 s) origin 0.000000 seconds MCHit 0 Status: 404 IP: 66.87.73.51:12866 URL: http://mmdai-linear-west-03.timewarnercable.com/speclive.video.cdn.charter.com/LIVE/1028/hls/ae/FX2_HD/.swne0c89ee6-59b0-4e1b-bf9c-005056b23b1dapple2apple/.rate_433152/index_v_433152_1.m3u8?nw=376521&prof=376521:twc_hls_live&mode=live&vdur=600&caid=FX_LIVE&csid=stva_android_ph_live&vcid=3f1749c5-7a19-40b2-8d3c-d7264e89a366&z5=62269&ads=VAST_LIVE_LCHTR&tagset_nam... (id 65087410)

谢谢

【问题讨论】:

    标签: regex extraction


    【解决方案1】:

    'http://'一直到'm3u8',保存在捕获组L_URL中

    捕捉它的模式:

    (?<L_URL>https?:(?:(?!m3u8).*)m3u8)

    (?<L_URL>  // capture within group, named 'L_URL'
    https?:    // exactly 'http', then optionally 's'
    (?:        // grouped but not captured
    (?!m3u8)   // look ahead and don't match exactly 'm3u8'
    .*         // match anything 0 or more times
    )          // end of group
    m3u8       // exactly 'm3u8'
    )          // end of group
    

    Demo (PCRE)

    【讨论】:

    • 如何在名为 L_URL 的组中捕获?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-02
    • 2012-12-30
    • 1970-01-01
    相关资源
    最近更新 更多