Coda Chang Coda Chang - 1 year ago 142
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download