const regex = /(?:.*?^0\,){1}/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:.*?^0\\,){1}', 'gm')
const str = `"REC01",
"Recipe1",
10,
"",
"",
" ",
2000,
"0101",
" ",
" ",
"126",
"REC01",
" ",
0,
0,
5,
38.182,"11200","Ingredient1"," "," ","1",
12.121,"11800","Ingredient2"," "," ","1",
27.475,"30910","Ingredient3"," "," ","1",
2.020,"26200","Ingredient4"," "," ","1",
20.202,"C01","Ingredient5"," "," ","1",
0,
"REC02",
"Recipe2",
10,
"13/04/21",
"13/04/21",
" ",
1000,
"0101",
" ",
" ",
"17",
"REC02",
" ",
0,
0,
3,
61.600,"11200","Ingredient1"," "," ","1",
23.400,"30910","Ingredient3"," "," ","1",
15.000,"BR-F01","Ingredient6"," "," ","1",
0,
"REC03",
"Recipe3",
10,
"19/03/21",
"19/03/21",
" ",
1000,
"0103",
" ",
" ",
"28",
"REC03",
" ",
0,
0,
9,
64.450,"11200","Ingredient1"," "," ","1",
12.700,"30910","Ingredient3"," "," ","1",
2.000,"20600","Ingredient7"," "," ","1",
12.000,"27220","Ingredient8"," "," ","1",
0.320,"584","Ingredient9"," "," ","1",
0.830,"588","Ingredient10"," "," ","1",
0.050,"599","Ingredient11"," "," ","1",
0.040,"600","Ingredient12"," "," ","1",
7.610,"585","Ingredient13"," "," ","1",
0,`;
// 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