const regex = /\s*sources\s*:\s*\[(.*?)\]/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\s*sources\\s*:\\s*\\[(.*?)\\]', 'gm')
const str = `var player = new Clappr.Player({
sources: ["https://c8.videobin.co/hls/oudvgdb4lvtk2yixv7joeclsl26zirhqupniofc7s,rqmgzeecwdox4infaoa,icmgzeecwdjhatedksa,.urlset/master.m3u8","https://c8.videobin.co/oudvgdb4lvtk2yixv7joeclsl26zirhqupniofc7sicmgzeecwdjhatedksa/v.mp4","https://c8.videobin.co/oudvgdb4lvtk2yixv7joeclsl26zirhqupniofc7srqmgzeecwdox4infaoa/v.mp4"],
poster: "https://c8.videobin.co/i/01/00010/m5pbbn9strm5_xt.jpg",
width: "100%",
height: "100%",
disableVideoTagContextMenu: true,
maxBufferLength: 15,
parentId: "#vplayer"
,plugins: {"core": [ClapprThumbnailsPlugin,LevelSelector]}
,scrubThumbnails: {
backdropHeight: 60,
spotlightHeight: 60,
thumbs: thumbs
},maxBufferLength: 15,levelSelectorConfig: {
title: 'Quality',
labels: {
3: 'Higher',
2: '1080p',
1: '720p',
0: '480p',
}
}
});`;
// 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