const regex = /^[ \t]*(?>etaLearnW_enabled)[ \t]?=[ \t]?(?<etaLearnW_enabled>[01])[ \t]*[ \t]*;?/mg;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^[ \\t]*(?>etaLearnW_enabled)[ \\t]?=[ \\t]?(?<etaLearnW_enabled>[01])[ \\t]*[ \\t]*;?', 'mg')
const str = `%% LEARNING RATES and other HYPER PARAMETERS
lambdaInfomaxTerm = 1; %coeff before logdetT'T, 0 or 1
etaLearnW_enabled = 1;
etaLearnW_enabled = 1;
% etaLearnW_enabled = 1;
%etaLearnW_enabled = 1;
etaLearnW = 1E-4;
%lambdaRidgeW = 3e-3; %going down, crashes on epoch 3888
lambdaRidgeW = 3e-2;
etaLearnK_enabled = 1;
etaLearnK = 4E-5;
%PostSlim:
%lambdaRidgeK = 3e-5; %too weak (going down fast)
%lambdaRidgeK = 3e-4; %too weak (fails at #14628)
lambdaRidgeK = 1e-3;`;
// 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