regexcoldfusioncfdirectory

how to use a filter using regex in Coldfusion


New to coldfusion, new to regex...

I have a directory of files, named with "some" followed by a 13digit number, followed by underscore, ID and file ending like so:

  some0000000000000_ID.jpg

ID can be any string.

How would I get the ID using regex? I guess I'd be looking for something like this, which captures everything between the underscore and file ending dot:

  _\A[A-Z]*[a-z]*[0-9]*$

but I'm really not getting anywhere. Can someone point me in the right direction?

Thanks!

EDIT:
I ended up doing it like this, which is hack-ish but works nicely:

<cfset cropFront = #ListRest(ReReplaceNoCase(name, ".png|.jpg", ""), "_")#>
<cfset cropFull = #ListFirst(ReReplaceNoCase( cropFront, "xxxxx", ""), "." )#> 

Maybe useful for someone else, too!


Solution

  • <cfdirectory name="images" directory="#path#" filter="some?????????????_ID.jpg">
    

    The filter is not a regex pattern. It only knows the ? and * wildcard characters.