Regex multiline javascript M3U list

669 Views Asked by At

I have this:

#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

I need a regual expression in javascript with two capturing groups:

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

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

..... and so on.

1

There are 1 best solutions below

2
On

Regex

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

Description

\# 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)

Output

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`