const regex = /(\w+)\s*=\s*(?:(?:"([^"]*)"|'([^']*)'|([^;\n"']+))\s*(?:;|$))/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\w+)\\s*=\\s*(?:(?:"([^"]*)"|\'([^\']*)\'|([^;\\n"\']+))\\s*(?:;|$))', 'gm')
const str = `param1=abc
param2 = abc
param3 = "ab'c"
param4='a"b"c'
param5="abc=def"
param7="hello'
(\\w+) - Elkapja a paraméter nevét.
\\s*=\\s* - Keresi az egyenlőségjelet a felesleges szóközökkel együtt.
(?:"([^"]*)"|'([^']*)'|([^;\\n"']+)) - Elkapja az értéket a következő feltételekkel:
"[^"]*": Dupla idézőjelek közötti szöveget, ami nem tartalmaz további dupla idézőjeleket.
'[^']*': Egyszerű idézőjelek közötti szöveget, ami nem tartalmaz további egyszerű idézőjeleket.
[^;\\n"']+: Szöveget, ami nem tartalmaz sem pontosvesszőt, sem sorvégét, sem idézőjelet.
\\s*(?:;|\$) - Keres egy opcionális sorvégi vagy pontosvessző elválasztót.`;
// 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