I have a saved clipboard with a file path ending in a file name. I would like to remove the name from the from the path but I'm having trouble understanding how to do that in Regex. I'm thinking I can just find .pdf and work back to the first / but I'm not that familiar with regex.
The file name always ends in .pdf and I want to remove the name up to the first /
It would look like this and I want to remove the end(bold text). Any suggestions how I would go about this?
April 21, 2021, 7:43pm
Will this RegEx search work for you?
This is very useful, but is there a way to reverse it. Selecting the last part instead of the first?
April 21, 2021, 8:37pm
I know this doesn't use regex, but it is very simple:
What. Dang. Of course it would be that easy, so great, thank you!
So... You want to remove the parent path and keep the file name – yes?
I think this was not quite clear in your OP.
@tiffle's given you the simplest method.
It's not difficult with RegEx though:
RegEx tends to be greedy unless set to
not greedy, therefore the pattern finds from the beginning of the string through the last available backslash.
@tiffle has provided a direct solution for you, but I'd like to offer these suggestions:
It is best to save plain text in a KM Global Variable, rather than in a Named Clipboard.
In addition to the KM
Filter action, you can also use the Split Path action to get one or more parts of the path.
Both of these are better than using RegEx for this use case.
I really appreciate you pointing both of these, they will be well used, thank you!
So this is working great but for some reason I cannot get the bold style to apply in the email. Does someone know why this isn't working?
Mail actions don't support styled text.
Neither does AppleScript per se, although there is a way around that using AppleScriptObjC.