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.
It just occurred to me, if your purpose is to get the path that contains your file, then the best way is probably not to use RegEx, because your file name may contain characters that have special meaning in RegEx.
In the example above, because the file name contains brackets and - inside the brackets, it has special meaning in RegEx. A RegEx search will not find what we want. But the if variable contains the filename returns true.
If you want to get the full path that contains your file name, then you can loop through the text, like this:
Thanks for pointing that out. I did not look carefully enough.
Yes. That was my thought too.
I was thinking of either adding a break from loop action or a cancel this macro action to the macro, depending whether @freewind1974 needs a multiple match or what else he wants to do with the match result.
I got lost following the conversation, so I better explain what I wanted to achieve and how I did it.
It's a bit hard for me to share the macros right now... I'll try my best to explain them.
I mix and master records in Pro Tools.
I built a lot of macros inside PT: recently, I wanted to get a more intuitive (for me personally) Open Session function.
Instead of getting a "recent files" list, with very long paths (on different drives) and the session names at the end (that is, difficult to read), I thought of using a "Prompt with list" window, with just the session names (in alphabetical order), filter them the way I want (for example, typing "MIX" I get only the mixing sessions, "MST" for mastering sessions, and so on), associate the corresponding path and open the session automatically.
I jump between sessions much quicker this way.
So, in order to keep track of the sessions I progressively open, I did this:
When PT's "focused window title changes", I get the session path + name from PT's Edit Window, if at the front;
I have a couple variables, one with full session paths + names, the other with session names only. The order of course is the same.
The entries for both variables are separated by %Return% and I already was adding a "/" on top of the path before writing here.
If the current session is not already contained in the variables, it gets added;
When closing PT, those variables are saved into txt files, and reloaded when PT reopens.
A separate macro deletes all history (files + variables) when needed.
With Option+O (my Open macro), I get prompted with the list of session names, alphabetically ordered. Then I got stuck about using RegEx with variables, and came here.
I couldn't make @martin suggestions work; I adapted @ccstone solution and it worked perfectly.
The path gets correctly associated.
Furthermore, once I open Pro Tools Finder with Cmd-O (regular Open Session PT command):
I paste the complete session name with Shift-Cmd-G;
What we were talking is mainly about RegEx. As I said, when you have a variable in a RegEx search, make sure you understand you are searching for literal characters or you want some special characters to be interpreted by RegEx. In your case, you need to search for literal strings. @ccstone has done this for you by adding an escape character to the variable string. Other wise, a dot . in RegEx matches any character (except for line terminators). For instance, myfile.txt will not only match /path/to/myfile.txt, it will also match /path/to/myfile$txt, /path/to/myfileAtxt, /path/to/myfile-txt, etc.
From what I understand about your purpose, I think, with some modifications, the macro below should work for you.
See screenshot below for instructions.
To ensure the hot key is sent to your desired app, Pro Tools, it is better to use the "Send To" option. I don't have PT. So I set it to Finder. You may change it to PT. In a series of keystrokes, adding pauses might be necessary in many cases. I added an example for you.
The slash / in the "end with" condition is needed. Otherwise, myfile.txt will match /path/to/myfile.txt and /path/to/anycharactersmyfile.txt.