const regex = /(?:--.*)|(?:\/\*)+?[\w\W]+?\n\*\//gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:--.*)|(?:\\\/\\*)+?[\\w\\W]+?\\n\\*\\\/', 'gm')
const str = `--GO
--SET ANSI_NULLS ON
--GO
--SET QUOTED_IDENTIFIER ON
--GO
/*
DECLARE @Gas SMALLDATETIME = '1/1/2016',
@System VARCHAR(Max) = '30',--'12,76,466,465,30,226',
/*following param is to help decide Transportation or Storage */
@Contract INT = 0,--Transport or (1 = storage).
/*following param is to help decide dth or %*/
-- Contract Period 0 = 5 Years, 1 = 10 years,..., 4=25 years
*/`;
// 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