const regex = /(?mis)^\bgeneral( #[0-9])?(.*?)^\s*$/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?mis)^\\bgeneral( #[0-9])?(.*?)^\\s*$', '')
const str = `General
Complete name : C:\\Projects\\Foray\\MediaEngine\\SampleMedia\\flv\\small.flv
Format : Flash Video
File size : 296 KiB
Duration : 5s 560ms
Overall bit rate mode : Variable
Overall bit rate : 436 Kbps
Writing application : Lavf52.103.0
Video
Format : Sorenson Spark
Codec ID : 2
Duration : 5s 560ms
Bit rate : 781 Kbps
Width : 320 pixels
Height : 240 pixels
Display aspect ratio : 4:3
Frame rate mode : Constant
Frame rate : 25.000 fps
Bit depth : 8 bits
Bits/(Pixel*Frame) : 0.407
Stream size : 530 KiB
Audio
Format : MPEG Audio
Format version : Version 1
Format profile : Layer 3
Codec ID : 2
Codec ID/Hint : MP3
Duration : 5s 512ms
Bit rate mode : Variable
Bit rate : 63.8 Kbps
Channel(s) : 1 channel
Sampling rate : 44.1 KHz
Compression mode : Lossy
Stream size : 42.9 KiB (14%)
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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