const regex = /if \(([^\$]+\$\<\>[^ ]+)[^\}]+\(null, ([^;]+)\);\s+}\s+([^;]+)\1(.*;)/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('if \\(([^\\$]+\\$\\<\\>[^ ]+)[^\\}]+\\(null, ([^;]+)\\);\\s+}\\s+([^;]+)\\1(.*;)', '')
const str = `get
{
int num;
lock (this.queueLock)
{
if (Journal.CS\$<>9__CachedAnonymousMethodDelegate7 == null)
{
Journal.CS\$<>9__CachedAnonymousMethodDelegate7 = new Func<ApiBlob, int>(null, (ApiBlob blob) => Encoding.UTF8.GetByteCount(blob.DataString));
}
num = this.Sum<ApiBlob>(Journal.CS\$<>9__CachedAnonymousMethodDelegate7);
}
return num;
}
}`;
const subst = `\3\2\4`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
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