Hey @freewind1974,
When asking for help if at all possible please upload a “working” macro that demonstrates your use-case in the minimum possible steps.
Like so:
RegEx ⇢ Extract a File Path Using a Variable in the Regular Expression v1.00.kmmacros (8.9 KB)
When posting macros to the Keyboard Maestro forum please use these guidelines:
- Always post a Macro File.
- Always post an image.
This means people won't have to reinvent the wheel to test your macro, and that significantly improves the likelihood that someone will help you.
Also a good rule-of-the-thumb is – “If you're not testing you're guessing.” – and guessing quite often wastes a lot of everyone's valuable time.
The same often holds true of written descriptions of problems. They tend to leave out crucial details.
Folks generally won't download something they haven't eyeballed first, so an image of the macro is crucial.
If you haven't seen these they're worth a moment of your time:
How to Post Your Macro to the Forum
Tip: How Do I Get The Best Answer in the Shortest Time?
-
Never use
%VariableName%
as a variable notation, while it's legal it should NOT be – because it's the same as KM's text-token notation. If you use it then you can't tell at a glance the difference between Tokenized-Variable-Names and actual Text-Tokens. -
RegEx101.com is a great resource, but there are some subtle differences between the regex variants they make available and the ICU regular expression set Keyboard Maestro uses.
- You must also pay close attention to the RegEx Flags that have been set.
-
Note that
myfile.txt
contains a regex metacharacter that needs to be escaped. -
Note that this pattern
^.*myfile.txt.*$
is potentially dangerous – it can accidentally match any string in the path – not just the file name. -
Note that
multiline
is NOT on by default in Keyboard Maestro, so when you're anchoring to the start of a line (not the entire string) you need to turn it ON.(?m)<your-regex>
To clarify – all code posted to the forum should be properly fenced.
You can use the Pre-Formatted Text button in the forum editor:
Which also responds to ⌘⇧C
For further information please see this link:
Code Block Fencing on the Keyboard Maestro Forum and Paste AppleScript as Markdown Macro
--
Take Care,
Chris
(Keyboard Maestro Moderator)