Clipboard modification on copy by regex?

Here's the code from my solution posted above to anyone curious:

let replacements = {
  d5ASD: "DSM 5 Autistic Spectrum Disorder",
  DID: "Dissociative Identity Disorder",
  "some space from": "Just to show how it looks with spaces in between from items",
async function clipboardManip() {
  let clip = await get_clipboard_content();
  if (clip.match(/Med5/)) {
    let text = clip;
    Object.keys(replacements).forEach(function eachKey(from) {
      to = replacements[from];
      text = replaceGlobally(text, from, to);
    await set_clipboard_content(text);
    return "Replacements done, please paste again.";
function replaceGlobally(original, s, re) {
  return original.replace(new RegExp(s, "g"), re);

/* copy from here */
let fail = `
This is a test, I have d5ASD.
DID is a thing a few of my friends have
I did be cute
some space from
/*to here*/
1 Like