Want to add more than one tag within my draft script - help :)

I have a script that I use all of the time that scans the draft note and adds task to a project. It will also add a “tag” to the task. Here is an example of how I did that:

const taskNoteDivider = "||";

// Add  + 👨‍🔬Lee - -
function processDraft(p_strIdentifier, p_strNewPrefix = "")
{
	// Check each line of the current draft
	for (let strLine of draft.lines)
	{
		// If the line starts with the task prefix, process it
		if (strLine.startsWith(p_strIdentifier))
		{
			// check if the divider is included in the task
			let taskName = "";
			let taskNote = "";
			if(strLine.includes(taskNoteDivider)){
				// split the line into the task name and the content for the note
				let lineContent = p_strNewPrefix + strLine.substring(p_strIdentifier.length);
				let lineParts = lineContent.split(taskNoteDivider);
				taskName = lineParts[0];
				taskNote = lineParts[1] + "\n" 
			} else {
				taskName =  p_strNewPrefix + strLine.substring(p_strIdentifier.length);
				// taskNote = draft.permalink;
			}
			// Build and call the URL
			let cb = CallbackURL.create();
			cb.baseURL = "omnifocus:///add";
			cb.addParameter("name", taskName);
			cb.addParameter("note", taskNote);
			cb.addParameter("project", draft.displayTitle);
			cb.addParameter("context", "👨‍🔬Lee_Alnes");
			cb.addParameter("autosave", "true");
			cb.open();
		}
	}
	return;
}

//Call the function to process the draft with the identifier and the optional prefix to use in OmniFocus.
processDraft("+ ", "👨‍🔬 Lee ");

The problem with this is that I have to add the “tag” as a script each time. For example, if I want a tag to be “Lee”, I have to script out how to create it. The limitation is one tag per task and i have to pre script every tag before hand.

What I would like to do is write a script that will scan the draft note for the task that I have setup and be able to add “tags” by using the “#” in front of text. I saw this script that did this however it didn’t keep the task in the project that I had setup:

// Full Featured (and contrived) Example:
// Write presentation !Friday #work
// Research Mother's Day gifts @1w !(5/12/2019) --Flowers are boring
// Asparagus #shopping
// #personal
// @2d

// SCRIPT BEGINS BELOW

// Split draft's contents into lines.
const lines = draft.content.split("\n");

// Compile our globally applied tags.
// Tags can be spread across multiple lines starting with #, and each word on a line becomes a tag.
var globalTags = [];
for (var line of lines) {
    if (line.startsWith("#")) {
        const tmp = line.split("#")[1];
        const words = tmp.split(" ");
        for (var w of words) {
            globalTags.push(w);
        }
    }
}

// Grab the globally applied defer date if it exists.
var globalDeferDate = null;
for (var line of lines) {
    let defer_global_rx = /^@\(([^)]+)\)|^@(\S+)/i;
    let match = line.match(defer_global_rx);
    if (match) {
        if (match[1]) {
            globalDeferDate = match[1];
        }
        if (match[2]) {
            globalDeferDate = match[2];
        }
    }
}

// Grab the globally applied due date if it exists.
var globalDueDate = null;
for (var line of lines) {
    let due_global_rx = /^!\(([^)]+)\)|^!(\S+)/i;
    let match = line.match(due_global_rx);
    if (match) {
        if (match[1]) {
            globalDueDate = match[1];
        }
        if (match[2]) {
            globalDueDate = match[2];
        }
    }
}

var taskPaper = '';

// Parse our tasks.
for (var line of lines) {
    if (line.startsWith("#") || line.startsWith("@") || line.startsWith("!")) {
        continue;
    }

    if (line.length == 0) {
        continue;
    }

    // Is there a note on the task? If so, grab it, and remove it from the line.
    var note = null;
    let note_rx = /--(.+)$/;
    let noteMatch = line.match(note_rx);
    if (noteMatch) {
        note = noteMatch[1];
    }
    line = line.split(note_rx)[0];

    // Grab the tags.
    var tags = [];
    let tags_rx = /#(\S+)/g;
    while (t = tags_rx.exec(line)) {
        tags.push(t[1]);
    }
    
    // Merge in the global tags.
    for(var gt of globalTags) {
        if(!tags.includes(gt)) {
            tags.push(gt);
        }
    }

    // Grab the defer date.
    var defer = globalDeferDate;
    let defer_rx = /@\(([^)]+)\)|@(\S+)/i;
    var deferMatch = line.match(defer_rx);
    if (deferMatch) {
        if (deferMatch[1]) {
            defer = deferMatch[1];
        }
        if (deferMatch[2]) {
            defer = deferMatch[2];
        }
    }

    // Grab the due date.
    var due = globalDueDate;
    let due_rx = /!\(([^)]+)\)|!(\S+)/i;
    var dueMatch = line.match(due_rx);
    if (dueMatch) {
        if (dueMatch[1]) {
            due = dueMatch[1];
        }
        if (dueMatch[2]) {
            due = dueMatch[2];
        }
    }

    // Remove the tags, defer and due dates from the line.
    line = line.split(tags_rx)[0];
    line = line.split(defer_rx)[0];
    line = line.split(due_rx)[0];

    // Build the TaskPaper version of our task.
    taskPaper = taskPaper + "- " + line + " ";

    if (tags.length > 0) {
        let tagStr = tags.join(",");
        taskPaper = taskPaper + "@tags(" + tagStr + ") ";
    }

    if (defer) {
        taskPaper = taskPaper + "@defer(" + defer + ") ";
    }

    if (due) {
        taskPaper = taskPaper + "@due(" + due + ") ";
    }

    if (note) {
        taskPaper = taskPaper + "\n\t" + note;
    }

    taskPaper = taskPaper + "\n";
}

// Create our OmniFocus callback object.
var cb = CallbackURL.create()
cb.baseURL = "omnifocus://x-callback-url/paste";
cb.addParameter("content", taskPaper);
var success = cb.open();
if (!success) {
    context.fail();
}

I’m looking for some help to create a script that has the best of both of the examples.

I am not a programer but tinker around. I would love some feedback or even would be willing to work with someone directly (pay) to get what I need.

Thanks!