I'm trying to manually pull the digests off of Rails assets (don't ask). I was directed to ZMV for easy regex-based find/replace. But the normal {32}
syntax for specifying an amount of repetition does not work:
$ zmv -n '(**/)(*)' '$1${2//-[A-Za-z0-9]\{32\}/}'
I've tried some other formats. This, for example, works, but is too greedy (it will turn image-3.png
into image.png
, for example):
$ zmv -n '(**/)(*)' '$1${2//-[A-Za-z0-9]##\./.}'
That double-hash syntax only showed up after a lot of Googling (I'd have expected +
). But I cannot for the life of me find how to make {32}
work. I tried #32#
? Which appeared to work, but that's because it was reading it as (in my eyes) ?32?
and that means it met anything that had a three in the digest or last character.
How do I signify character repetition in zmv?
EDIT:
Apparently it would help some to view filenames I'm trying to match? To be clear: my question is "how do I signify character repetition in zmv" not "how do I match these filenames" (a question I know the answer to in standard RegEx format). If it helps, here is my intended before and after:
directory/asset-jej4jtifne9bjkkeuwr09rewrewlur23.css
another-directory/style-748reiodlpqwerntaerwerwerexfzsdf.js.gz
directory/subdirectory/this-is-a-thing-qwertyuiopasdfghjklzxcvbnm123456.js
third-directory/should-not-match-3.css
Should become:
directory/asset.css
another-directory/style.js.gz
directory/subdirectory/this-is-a-thing.js
third-directory/should-not-match-3.css
SECOND EDIT:
Because I needed to do this yesterday, I did it the long way and (as expected) it worked. I'd still like to know how to avoid it in the future. Here's the command I ended up using (I repeated my character matcher 32 times explicitly):
$ zmv '(***/)(*)' '$1${2//-[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]/}'
THIRD EDIT:
For the record, I'm using zsh on OS X. I'd imagine zmv is the same across platforms, but I couldn't say for sure.