XML文档正则表达式

问题描述 投票:0回答:1

我正在尝试为XML文档提供一个正则表达式,它实际上是DASH mpd文件。用例是该XML文档具有AdaptationSet标记,该标记又可以具有多个Representation标记,如图所示。我需要匹配所有具有bandwidth属性大于指定输入(即如下所示的20000004000000)的表示形式标签。我可以提出以下示例,但它不能解决属性跨越多行的情况,如用id = 1表示中所示。

正则表达式中的RANGE可以取1-9之间的任何值,可以假定其为整数格式,可供正则表达式使用。后面6位数字的RANGE将根据RANGE的值分别是1还是2或3来匹配带宽值1000000或2000000或3000000,依此类推。

regex:

<[Rr]epresentation.*?[Bb]andwidth="0?[%(RANGE)]\d{6}"[\s\S]*?[Rr]epresentation>

    <AdaptationSet segmentAlignment="true" maxWidth="1280" maxHeight="720" maxFrameRate="24" par="16:9">
     <Representation id="1" 
        mimeType="video/mp4" 
        codecs="avc1.4d401f" 
        width="512" 
        height="288" 
        frameRate="24" 
        sar="1:1" 
        startWithSAP="1" 
        bandwidth="1000000">
        <SegmentTemplate timescale="12288" duration="61440" media="BBB_512_640K_video_$Number$.mp4" startNumber="1" initialization="BBB_512_640K_video_init.mp4" />
      </Representation>
      <Representation id="2" mimeType="video/mp4" codecs="avc1.4d401f" width="512" height="288" frameRate="24" sar="1:1" startWithSAP="1" bandwidth="2000000">
        <SegmentTemplate timescale="12288" duration="61440" media="BBB_512_640K_video_$Number$.mp4" startNumber="1" initialization="BBB_512_640K_video_init.mp4" />
      </Representation>
      <Representation id="3" mimeType="video/mp4" codecs="avc1.4d401f" width="768" height="432" frameRate="24" sar="1:1" startWithSAP="1" bandwidth="4000000">
        <SegmentTemplate timescale="12288" duration="61440" media="BBB_768_1440K_video_$Number$.mp4" startNumber="1" initialization="BBB_768_1440K_video_init.mp4" />
      </Representation>
    </AdaptationSet>

我正在尝试为XML文档提供一个正则表达式,它实际上是DASH mpd文件。用例是该XML文档具有AdaptationSet标记,而该标记又可以具有多个Representation ...

python html regex xml pcre
1个回答
0
投票

不使用正则表达式,但这是我要做的:

© www.soinside.com 2019 - 2024. All rights reserved.