const regex = /matei 140 for /gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('matei 140 for ', 'gm')
const str = `<?php
\$days = 7; // Eine Woche
\$activity = "Laufen"; // Trainingsart
\$duration = 30; // Minuten pro Tag
for (\$day = 1; \$day <= \$days; \$day++) {
echo "Am Tag \$day bist du \$duration Minuten \$activity gewesen.<br>";
}
\$activities = ["Laufen", "Schwimmen", "Radfahren", "Yoga", "Krafttraining"];
\$motivation = 5; // Skala 1-10
\$goal = "fit werden"; // Ziel
\$duration = 30; // Minuten pro Tag
\$days = 7; // Eine Woche
for (\$day = 1; \$day <= \$days; \$day++) {
\$activity = \$activities[(\$day-1)%count(\$activities)];
echo "<br>Tag \$day: Heute machst du \$duration Minuten \$activity, Motivation: \$motivation/10, Ziel: \$goal.";
\$motivation++;
if(\$day == \$days){
echo "<br>";
}
}
function wochenplan(\$activities, \$days, \$dauerProTag) {
\$gesamt = 0;
for (\$i = 1; \$i <= \$days; \$i++) {
\$activity = \$activities[array_rand(\$activities)];
echo "<br> Tag \$i: \$activity für \$dauerProTag Minuten.";
\$gesamt += \$dauerProTag;
if(\$i == \$days){
echo "<br><br>";
}
}
return \$gesamt;
}
\$activities = ["Laufen", "Schwimmen", "Radfahren", "Yoga", "Krafttraining"];
\$gesamt = wochenplan(\$activities, 7, 30);
echo "Gesamtzeit: \$gesamt Minuten.";
`;
// 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