const regex = /matei 115 variables/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('matei 115 variables', 'gm')
const str = `<?php
\$name = "Matei";
\$age = 16;
\$birthplace = "Klagenfurt";
\$bench_pr = 95;
\$five_k_pr = "23:51";
\$running_distance = 5;
echo "There was once someone named \$name who was \$age years of age. <br>
He was born in \$birthplace. He benched \$bench_pr kg and ran \$running_distance km in \$five_k_pr";
`;
// 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