Ok this works to make the updates.
Note that I am including this on my people notes which have frontmatter and the body is only dataviewjs. So the file structure / length /content is well understood.
function replaceAlias(y, x) { // Define the regex to match the alias pattern
const regex = /(aliases:\n\s{2}-\s)(.+?) \((.+?)\)/; // Replace the matched part with the new alias using x
return y.replace(regex, `$1${x}`); }
// Get the current file path
const filePath = dv.current().file.path;
const file = app.vault.getAbstractFileByPath(filePath);
let contents = await app.vault.read(file);
let newname = dv.current().file.frontmatter["full-name"] + " (" + dv.current().file.frontmatter.company + ")"
const newContent = replaceAlias(contents, newname);
//dv.paragraph(newname);
app.vault.modify(file, newContent)