joeynotjoe Posted January 27, 2017 Share Posted January 27, 2017 Hello! I'm writing a workflow based on a file action, and at one point in there, I would like to use the replace / regex function to extract just the filename, without the full path or the extension. I've tried googling and trying a bunch of options, but I haven't had the time to fully ingest Regex properly yet, and nothing I've found has worked. Anyone care to help me out? :-D Here's an example of a full path I'm working with: ~/Desktop/Testing.mov I would like to just extract "Testing". I hope one day I can look back at how silly it was to ask such a basic question like this. Thanks so much in advance! Link to comment
vitor Posted January 27, 2017 Share Posted January 27, 2017 This should work: .*\/(.*)\..* in the regex, and replace with $1. Explanation: .*\/ is “everything until the last /” (i.e. the path without the filename); (.*) is “capture anything” (the parenthesis are the “capture” part which will then be output by $1); \..* is “everything from the last . until the end of the string” (i.e. the extension). joeynotjoe 1 Link to comment
joeynotjoe Posted January 28, 2017 Author Share Posted January 28, 2017 Worked like a charm, and I really appreciate the explanation! Why my search attempts to find this answer failed me was due to me not including anything in the replace section. Duh. Cheers! vitor 1 Link to comment
FroZen_X Posted January 28, 2017 Share Posted January 28, 2017 2 hours ago, joeynotjoe said: Worked like a charm, and I really appreciate the explanation! Why my search attempts to find this answer failed me was due to me not including anything in the replace section. Duh. Cheers! This site might help you like it helped me: http://regexr.com/ I use it to test Regex and it has good explanations. joeynotjoe 1 Link to comment
vitor Posted January 29, 2017 Share Posted January 29, 2017 4 hours ago, FroZen_X said: This site might help you like it helped me: http://regexr.com/ I use it to test Regex and it has good explanations. It’s also the site recommended in the Alfred documentation. Link to comment
FroZen_X Posted January 29, 2017 Share Posted January 29, 2017 19 hours ago, vitor said: It’s also the site recommended in the Alfred documentation. oh ok, I didn't know that lol I found that one the other day as I had to test a regex for a keyboard maestro macro But that's cool Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now