【问题标题】:Regex multiline javascript M3U list正则表达式多行 javascript M3U 列表
【发布时间】:2016-05-26 00:20:54
【问题描述】:

我有这个:

#EXTM3U
#EXTINF:-1,ABC HD
http://AAAAAAAAAAAAAAA/BBBBBBBBBBBBBB/C.ts
#EXTINF:-1,DEF HD
http://FFFFFFFFFFFFFF/DDDDDDDDDDDDDDDDD/C.ts
#EXTINF:-1,GHI HD
http://SSSSSSSSSSSSSS/GGGGGGGGGGGGGG/C.ts

我需要一个带有两个捕获组的 javascript 正则表达式:

 (1) ABC HD
 (2) http://AAAAAAAAAAAAAAA/BBBBBBBBBBBBBB/C.ts

 (1) DEF HD
 (2) http://FFFFFFFFFFFFFF/DDDDDDDDDDDDDDDDD/C.ts

.....等等。

【问题讨论】:

    标签: javascript regex m3u


    【解决方案1】:

    Regex

    (http:\/\/(?:[a-zA-Z\/]+)\.ts)
    

    说明

    \# matches the character # literally
    EXTINF: matches the characters EXTINF: literally (case sensitive)
    [^,]+ match a single character not present in the list below
        Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
        , the literal character ,
    , matches the character , literally
    1st Capturing group ([^\n]+)
        [^\n]+ match a single character not present in the list below
            Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
            \n matches a line-feed (newline) character (ASCII 10)
    \n matches a line-feed (newline) character (ASCII 10)
    2nd Capturing group (http:\/\/(?:[a-zA-Z\/]+)\.ts)
        http: matches the characters http: literally (case sensitive)
        \/ matches the character / literally
        \/ matches the character / literally
        (?:[a-zA-Z\/]+) Non-capturing group
            [a-zA-Z\/]+ match a single character present in the list below
                Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
                a-z a single character in the range between a and z (case sensitive)
                A-Z a single character in the range between A and Z (case sensitive)
                \/ matches the character / literally
            \. matches the character . literally
            ts matches the characters ts literally (case sensitive)
    

    输出

    MATCH 1
        1.  [19-25] `ABC HD`
        2.  [26-68] `http://AAAAAAAAAAAAAAA/BBBBBBBBBBBBBB/C.ts`
    MATCH 2
        1.  [80-86] `DEF HD`
        2.  [87-131]    `http://FFFFFFFFFFFFFF/DDDDDDDDDDDDDDDDD/C.ts`
    MATCH 3
        1.  [143-149]   `GHI HD`
        2.  [150-191]   `http://SSSSSSSSSSSSSS/GGGGGGGGGGGGGG/C.ts`
    

    【讨论】:

    • 它没有捕获第一组:-/
    • @Polarix 哦抱歉刚刚看到更新
    猜你喜欢
    • 2022-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多