const regex = /([A-Z^\.]+\.(?:[^\[]+| ?)\[[^\]]+[^\s]+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('([A-Z^\\.]+\\.(?:[^\\[]+| ?)\\[[^\\]]+[^\\s]+)', 'gm')
const str = `VB.Bar-1[TEST-Insert.2]Val_1 = B.Bar-1[PC83-AB2.1]In1 && B.Bar-1[PC83-AB2.1]In2
VB.Bilozerka-1[TEST-Insert.2]Val_2 = B.Bilozerka-1[ТП1.1]Пуск_захисту && B.Bilozerka-1[ТП1.1]Спрацьовування_захисту_iнвертора
VA.Bar-1[TEST-Insert.3]Val_3 = A.Bar-1[DirisA40.1]V3 && A.Bar-1[DirisA40.1]P
VA.Dashev-1[TEST-Insert.3]Val_1 = A.Dashev-1[ТП-5.2 AC]C_active_power && B.Dashev-1[ТП-5.2 AC]PV_input_power`;
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