Drafts Action Directory

Replace Example

Posted by agiletortoise, Last updated: 2018-07-04 13:36:12 UTC

Example script showing how to create a saved regular expression replace action. Edit the regular expression and replaceWith variables at the top to modify for different saved replacement function.

Install

Steps

  • script

    // define regex to use...
    const findRegex = /([A-Za-z]*) ([A-Za-z]*)/g;
    // define replacement expression...
    const replaceWith = "$2 $1";
    
    // do the replacement...
    draft.content = draft.content.replace(findRegex, replaceWith);
    draft.update();

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.