I’d like to convert some regular expressions into actions.
I’ve been trying to figure it out using the Draft Script Reference.
Could someone help me get started by helping me identify the different parts I need to include to create the following?
I think then I can get my head around the structure I need to follow to do the others…
The following regex searches for a word at the beginning of a line and deletes that line and proceeding empty lines until the next instance of text.
With this example, I’d like a prompt to come up where I can enter the text which should replace WORD in the ‘do something’
^(WORD$)\s*\n
Using the prompt example on the reference page, I’m guessing I need:
- to create a text prompt box
- have a button to push after the text is entered
- replace the text in the ‘do something’ (I’m not sure what that looks like with the do something line, is it
[[WORD]]
?) - then it should look for whatever was entered in the text field, and combine it with the ‘do something’
Below is not expected to work, but if someone could teach me how, I’d be very grateful to learn.
let p = Prompt.create();
p.addTextField("textFieldName", "Label", "");
p.addButton("First");
let didSelect = p.show();
let textFieldContents = p.fieldValues["textFieldName"];
if (p.buttonPressed == "First") {
draft.content = draft.content.replace(/^(WORD$)\s*\n /gm, "")
}