Extracting Code from Notification Text

Foxcie95

New member
I have set the trigger to the correct name and app for the notification. It does execute actions like interact with notification. But I can't get it to extract the text I want.

It appears in the body of the message and it comes in the same format every time. I'm trying to capture it like this - Code: codehere123. I have tested the string in regex101.com, and it finds the code successfully with letters and number.

I'm using regex /(?<=Code: )\w+. I tried using app name and notification text for source text like {appname}{not_sub_text}, is that wrong? If so, what can I use instead?

Whenever I try to run text manipulation in Macrodroid to extract, nothing appears in the clipboard or paste.


I have also tried running the macro with steps to click and open the notification, copy the message, open a note, paste it, and extract the text from the note page. Still nothing in the clipboard.

Additionally I also cannot get it to paste using UI interaction>Paste. I have to make it click the keyboard with x, y coordinates or locate identify in app.
 

420

Active member
I have a feeling that the first "/" has to be left out in MD, but i really don't know much about regex.. Is the text and code always the same length? If that is the case you could probably use text manipulation - substring instead.
 

Foxcie95

New member
The "/" is a part of the regex. But I got it working today, by changing the regex to /(?<=Code: )[a-zA-Z0-9]+. Now it's extracting the correct code. It's not always the same length, but it always ends on one line. So it extracts the code and nothing else.

Now everytime I get a Telegram notification with a keyword it starts the macro, extracts the code, saves it to clipboard, opens webpage, scrolls down, clicks and pastes.

And if notification comes when phone is locked it wakes the screen and enters my pattern. Works like a charm.
 
  • Like
Reactions: 420

Dimlos

Well-known member
It seems to be self-resolving, but I think this regex can be extracted as well.
 

Attachments

  • code_extract.jpg
    code_extract.jpg
    316.2 KB · Views: 16

Dimlos

Well-known member
Without the actual content of the notice, it would be impossible to test it reliably, so there is no way to do so.
I don't think you need to dig deeper since it seems to have resolved itself already.
 

Foxcie95

New member
I tested it by sending the notification through a dummy Telegram account with same group name and same message as the notification. So I did test your regex already.
 
Last edited:

Dimlos

Well-known member
Since you are the only one who knows the contents of the notice, the respondent has no way to verify it.
Remember that a regex cannot give you an exact answer unless you know the before and after of the string you want to extract.

Please do not write anything more as this is a pointless exchange.
 

Foxcie95

New member
I have tested your regex with the contents of the notification. I know the before and after of the string I want to extract. The text in question can to my understanding be extracted with "/(?<=Code: )[a-zA-Z0-9]+" only using a lookbehind because it begins on one line with "Code: " and ends on the same line followed by an empty paragraph and the next line of text underneath. That's how the text is formatted, the contents are irrelevant.

If the regex is incomplete with previous string and after, you could let me know where or what to put of my own text before and after.

These types of forums are for learning and sharing with each other, you're just making this very unpleasant and difficult.

I have just recently tried using regex, if you could have just explained how your regex is set up instead of telling me not to respond, that would have been alot better.

I will no longer be checking this post for replies, so you can save your energy.
 
Last edited:

OscariBot

Active member
Please @Foxcie95 This is a forum for exchanging ideas asper macrodroid like you rightly said. But I think @Dimlos was just trying to ease the conversation since you have already come up with a working rex that did exactly what you wanted. remember even though he is not obligated to respond to your thread but he spend sometime give your question a thought and then to came up with an idea that probably didn't work for you. he deserve some respect please..... I am responding because of @Foxcie95 last 3 paragraph above.
 
Top