const regex = /<[Rr]epresentation[^>]*?[Bb]andwidth="0?[2-9]\d{6}"[\s\S]*?[Rr]epresentation>/gms;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('<[Rr]epresentation[^>]*?[Bb]andwidth="0?[2-9]\\d{6}"[\\s\\S]*?[Rr]epresentation>', 'gms')
const str = `<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" minBufferTime="PT1.500000S" type="static" mediaPresentationDuration="PT0H9M54.00S" profiles="urn:mpeg:dash:profile:isoff-live:2011">
<ProgramInformation moreInformationURL="http://gpac.sourceforge.net">
<Title>/home/elkhatib/Documents/dash264/TestCases/2b/qualcomm/2_BBB_5Sec_MainProf/MultiRes.mpd generated by GPAC</Title>
</ProgramInformation>
<Period id="" duration="PT0H9M54.00S">
<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="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="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="1" 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="2" 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>
</Period>
</MPD>
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions