and like this (putting the email contents in a variable first, then searching the variable instead of the message contents directly:
I have also tried \t rather than \h; same result. [edit post to mention this]
I'm wondering if it has something to do with formatted html vs. text, because the mail message uses a table for the info I need – but it does paste into regex101 with tab characters between the columns. That's why I tried putting the text into a variable first, in hopes of getting around that:
I've looked at related discussions like this one and the wiki, which was how I knew to try \h rather than \t.
I'm sure it's user error; just not sure what. Thanks for any help!
CK
Sorry for the obvious question, but have you checked how the %MailContents% token is storing the text? Sometimes this is my issue when my regex works on regex101 but not in Keyboard Maestro. If that isn't the problem, you could try (?<=Track title)[^\S](.*)$ (with or without (?m)). I usually have success with lookbehind in KM, but I'm still learning and rely on some trial and error. [edit] Oh or you could just try [^\S] in place of \h or \t because that also works.
Oh, I see. Could you use a Display in a window action and share the relevant section of the mail contents so we can see what the regex needs to work on?
Solved! I simplified the regex and incorporated the \s title\s(.*)
Why does this work? It is, as @hemicyon and I both suspected, related to the formatting of the email. If I use just the title\s portion of the regex, you can see that instead of a Tab, we find a return:
So that's the ticket. Thanks, folks! I just needed to know what to try.
Copying from Mail will get you a bunch of different formats at once -- text, Rich Text, HTML if the email included that... Pasting into your browser involves picking the "best" of those, usually with some extra conversion -- in this case that looks the HTML version with table columns converted to tabs.
The %MailContents% token gets you the plain text contents -- if you look at the message source it'll be the part starting
That's why you need to view the source of the message to see what's going on here -- it'll all depend on how the plain text version of the HTML message is presented.
<tr><td>cell 1</td><td>cell 2</td></tr>
...might be
cell 1
cell 2
...in plain text, for example. And all that will depend on how the message was generated -- no point me sending myself an HTML message in Mail to demo because that'll almost certainly be different to what they use.
Throw on top of all that the fact that (I think...) the %MailContent% token actually gets the text from the email body via the message's content AppleScript property, and who knows what's happening!
Yes! I viewed the raw message and found an HTML table, with song title in a container.
The whole message appeared a second time in the raw data using ASCII characters, pipes, etc. to create table structure.
Not long after I figured the regex that would work, the left-side ports on my MacBook died, so after doing a soft reset, SMC reset and diagnostics, I took it to the Apple Store where that board's getting replaced. Hell of an afternoon.
Point being, I don't have the macro at hand, and here on my iPad, I don't see a way to view the raw message data or I'd post it for you.
@hemicyon and @Airy -
I'm sorry; I seem to really have offended both of you.
But... in the dark? In my initial post, I provided a link to the regex101 page, which includes the email text; a screenshot of it (the regex solution); images from two versions of my macro; a screenshot of the original mail so you could see how it was formatted (I didn't know at that time to show the raw message, sorry)...
No offense taken! We're trying to help, but it's difficult to pattern match without seeing the what the regex is actually matching, as Nige has explained.
But that text is not what was inside the token, which is why the regex wasn't working in Keyboard Maestro but was working on regex101. By the time I asked you to use a display in window action and share what was inside the token, you had already found a solution. When I said we were working in the dark, I meant you too! I don't know how you managed to get the result you were after without seeing what you working with, but you managed it somehow.
Not at all. I am motivated by altruism, ego and the desire to wake myself up in the morning. So if I'm giving you bad vibes, it's probably because I'm groggy.
Oh, geez. I must be spending too much time on Reddit if I’m assuming the crankiest interpretation!
I really appreciate everybody’s help.
As for how I figured it out, I tried each change suggested, and when one didn’t work, I would read up about it at regex101 and see if there was a variation that could possibly work. And I eventually hit the right one.