Coda Chang Coda Chang - 8 months ago 57
Ruby Question

Rails write regular expression to get folder name

This is a simple question, I want to clean up carrierwave picture after the Rspec test.

The picture file is in

, the string behind
will be a random string.

I want to get the folder name by
regular expression
, but it didn't work.

I've tried this

=> []
=> []

I am confused, because I use Rubular and it can extract these names.


Dir[] doesn't take a regular expression, it takes a shell wildcard expression. These might look superficially similar, especially with .* being a common feature in both, but they're not the same.

If you want to use a regular expression you have to fetch all entries and then filter them with something like grep.