Jump to content

Alfred Regex to extract just the filename?


Recommended Posts

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

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).

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...