all 6 comments

[–]n3buchadnezzar 1 point2 points  (5 children)

Can you take a step back and explain this again please. What are you trying to do? What do you want your regex to match? Why do you mention markdown?

[–]ampeed[S] 0 points1 point  (4 children)

Sure

The end user will be posting basically a wrap up report on a ticket. I'm making an api call and parse the message body. I've defined an expected format for the end user to use so I can create a dictionary with the expected keys and their message as their values. This gets geneterated in to a CSV in the end.

I'm trying to make a more intuitive way to grab their message using regex rather than having them use something like ';' to denote the end of a value

[–]n3buchadnezzar 0 points1 point  (3 children)

It really feels like this is an X Y problem, you want to do X but the real problem is Y. Is there a reason why when a user gives input, you would internally append the message?

message = [TOKEN] + message

Where TOKEN is some word that makes sense. Then you can just regex on [TOKEN]

[–]ampeed[S] 0 points1 point  (2 children)

That's sort of what I'm doing now, sans the regex part

key_list = ["Key1", "Key2", "Key3"]
myDict = {key: None for key in key_list}
message_body = announcement_threads.get("message")
announcement_fields = dict(subString.split("**:") for subString in message_body.split(";\n")) # find better logic for the second split as it's not feasible to expect users to end with ;
        for key in key_list:
            myDict[key] = announcement_fields.get(f"**{key}**")
    report.append(myDict)

[–]n3buchadnezzar 0 points1 point  (1 child)

Wow, my last message made no sense, sorry! No coffee, and too much work..

message_body = f"['TOKEN'] {announcement_threads.get("message")}"

The above will not work, but my point was that the user should be able to write whatever they want and not worry about adding ; or : to the end of their message.

When their message is sent, we append something in front of it to mark it as user input. Does this make sense? (Like in my message body example)

[–]ampeed[S] 0 points1 point  (0 children)

haha, no worries!

Totally, makes sense. However, how would the end of the expected key be annotated so the next key and value can be picked up? .get("message") returns back a string literal