Two script replacements

I use the following script:

let findRegex = /(“)(.*?)(”)/g;
let replaceWith = “„$2“”;
draft.content = draft.content.replace(findRegex, replaceWith);

What is the shortest way to replace another combinations of strings with this script?

Thanks and Merry Christmas!

Technically, for “shortest”, you could just do something like this as there seems no benefit really to having those variables, and you could do it in a couple of lines with only one forced update.

draft.content = draft.content.replace(/(“)(.*?)(”)/g, "„$2“").replace(/(::)(.*?)(::)/g, ";;$2;;");

But you could also make a function for reuse.

function replacer(p_strFind, p_strReplace)
    draft.content = draft.content.replace(p_strFind, p_strReplace);

replacer(/(“)(.*?)(”)/g, "„$2“");
replacer(/(::)(.*?)(::)/g, ";;$2;;");

if these don’t help, can you clarify what you are looking for by the term “shortest”?

1 Like