const regex = /^(?<![\s\S\r])(---\ntitle:\s)([1-9a-zA-ZÀ-ŰØ-űø-ÿ].*)([\d\D]*---\n\n#\s[1-9a-zA-ZÀ-ŰØ-űø-ÿ].*)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?<![\\s\\S\\r])(---\\ntitle:\\s)([1-9a-zA-ZÀ-ŰØ-űø-ÿ].*)([\\d\\D]*---\\n\\n#\\s[1-9a-zA-ZÀ-ŰØ-űø-ÿ].*)', 'gm')
const str = `---
title: Title can be anything
aliases:
- somealias
tags:
- sometag
topic: sometopic
anotheryamlKey: whatever
date created: 2022-12-14
date modified: 2023-10-06
---
# Title can be anything
First line of file.
Second line. `;
const subst = `$1$2$3\n\n%%\n\`\`\`query\nfile: "$2.md" /\\[\\[(?!.*\\|)([^[\\]]+#[^\\]]+)\\]\\]/\n\`\`\`\n%%`;
// 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