dqj96395 2018-10-17 16:23
浏览 96

Javascript RegEx命名组和组合

I want to parse a file containing multiple lines. I will loop through the newlines to extract the information i need. I am trying to write a m3u parser which uses regex - i already succesfully made one using sting position and substring.

I want to parse this line:

#EXTINF:-1 tvg-ID="NPO 2 HD NL" tvg-name="NL : Npo 2" tvg-logo="http://www.iptv-plus.net:25461/images/Astra23picon/1_0_19_17C0_C82_3_EB0000_0_0_0.png" group-title="Holland",NL : Npo 2

So i came up with these regexpressions:

(?<=group-title=")(.*?)(?=")
(?<=tvg-name=")(.*?)(?=")
(?<=tvg-logo=")(.*?)(?=")
(?<=tvg-ID=")(.*?)(?=")
(?<=,)(.*?)$

These will extract the tvg tags, and extract the name from the end of the line (always after the last occuring comma.)

What i would like is to put all these regexpressions in one regex, so i can get an array containing all elements. I tried using | but that is an OR? i believe.. I can use them seperate, but i think it might be faster to put them all in 1? Also i would like to create named groups. But when i change it to

(?<group><=group-title=")(.*?)(?=")

it takes the lookbehind as text (<=).. Can i and how can i combine lookbehind with named groups? I like to use the regex in javascript, but could also implement a php that parses the m3u file and returns a json.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动