This is my regex, and I'm wanting to part that says How to own the world
Works fine on regex101
When I input (?:[^-]-\s){2}(.*) into keyboard maestro though it's failing at runtime
This is my regex, and I'm wanting to part that says How to own the world
Works fine on regex101
When I input (?:[^-]-\s){2}(.*) into keyboard maestro though it's failing at runtime
Works fine here.
___tmp <4CE3 200225T130549>.kmmacros (3.4 KB)
Note:
I copied the expression from your regex101 link.
The expression in your OP above is missing some *
Tip: In a forum post, format your code and literal expressions as fenced code clock:
```
<your code here>
```
Thanks Tom, attached is the macro. Perhaps you can see where I'm going wrong as looks same to me.Move Book note .kmmacros (9.9 KB)
I can’t test your macro because it refers to too much things specific to your setup (like apps I don’t have installed).
The RegEx action looks fine. However, it seems that after the RegEx you are not using the variable you have captured the group into (Local Capture
). So —unless I’m missing something— the RegEx action is superfluous.
Hey Tom, attached is updated macro. I took yours and change search text for search system clipboard. I copy in my macro the text exactly the same, however it always keeps failing at run time. Unsure where in this it's possibly causing the issue.___tmpch.kmmacros (3.0 KB)
It still runs perfectly fine (with the text from your regex101 link as input on the clipboard) and returns
How to Own the World
But I think I see your “issue” now: You probably used a different input text where the RegEx does not match. In this case KM returns Search Regular Expression failed to match
and aborts the macro. This is the expected behavior.
If you don’t want it to abort the macro if the RegEx fails, then disable that option in the action’s settings (Gear menu):
If you don’t wan to see the “failed” message either, then disable also the Notify on Failure option.
BTW, you find all this info also on the KM Wiki, in this case here.
You can very easily access the specific help page for any action by selecting the Help menu item in the Gear menu of the action. (See screenshot above, last menu item.)
Thanks, I checked and yes the input text on different runs of this macros does come up as not matching.
The saver (or 'mattress stuffer') will put their ÂŁ5,000 lump sum into a current account that,as is effectively the case today, is paying no interest whatsoever .They then add ÂŁ250 a month into the same current account each month going forward . After one year the saver would have ÂŁ8,000 squirrelled away : the ÂŁ5,000 he or she started with , plus 12 payments of ÂŁ250 ( totalling ÂŁ3,000). - How to Own the World
This for instance returns no match when using
(?:[^-]*-\s*){2}(.*)
I thought the above regex would always pull out everything after the -
To confirm on every note the dash is at the end with the book name thereafter. Is there any regex that would suit that?
Your original text:
The Rational Optimist: How Prosperity Evolves by Matt Ridley /Abundance : The Future Is better Than You Think by Peter Diamonds and Steven Kotler./The Sixth Wave : How to Succeed in a Resource-limited World by James Bradfield Moody and Bianca Nogrady/ What's Mine is Yours: The Rise of Collaborative Consumption by Rachel Botsman and Roo Rogers. - How to Own the World
Your new text:
The saver (or 'mattress stuffer') will put their ÂŁ5,000 lump sum into a current account that,as is effectively the case today, is paying no interest whatsoever .They then add ÂŁ250 a month into the same current account each month going forward . After one year the saver would have ÂŁ8,000 squirrelled away : the ÂŁ5,000 he or she started with , plus 12 payments of ÂŁ250 ( totalling ÂŁ3,000). - How to Own the World
With your expression (?:[^-]*-\s*){2}(.*)
you are matching this sequence (simplified):
Zero times or more Anything but a hyphen, followed by a Hyphen, optionally followed by one of more spaces. The whole thing has to happen exactly two times {2}
.
Then followed by anything or nothing (the capture group).
It matches with the first text because you indeed have two hyphens there, one with “Resource-limited”, the other one before the “How”.
In your new text this is not the case. There is just one hyphen (before the “How”)
Change the {2}
to {1}
and it will work for the new text.
But for obvious reasons it will no longer work as expected for the first text (the capture group will start after the first hyphen). So, you should find a better RegeEx that works for both.
Paste both texts to regex101 and try to find a solution. Remember, if you work with the begin/end of line anchors (^
and $
) the m
flag ((?m)
in KM) makes a difference if the text has more than one line.
One more tip:
If your input text comes with correct punctuation, then the character before the “How to Own…” will most certainly not be a hyphen (-) but an en dash (–) or an em dash (—).
So, I would consider all three characters for the match.
Thanks for the guidance & support. I managed to work it out
.*-\s(.*?.*)
Seems to be working well
Great! Here another possibility:
\.\h+[-–—]\h+(.+)$
Of course, there are many solutions. But this seems quite safe and also has some tolerance. It requires a period after the description text, then one or more horizontal spaces, then either a hyphen or one of the dashes, then one or more horizontal spaces, followed by the obligatory book title as capture group at the end.