Comments (4)
Thanks for reporting this, I have been able to reproduce it. I will investigate the problem and find a fix.
In the meantime, you can do something like this:
f2 -f '(.*)\d.txt' -r '$1 %02d{{ext}}' -f ' ' -r '_'
┌──────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| ******************************** |
| test1.txt | test_01.txt | ok |
| test2.txt | test_02.txt | ok |
| test3.txt | test_03.txt | ok |
└──────────────────────────────────┘
from f2.
@d-Rickyy-b The solution is to use ${1}
.
Go uses $name
or ${name}
to represent capture variables where name
is a non-empty sequence of letters, digits, and underscores.
When you use something like $1
, it refers to the submatch at index 1. When you use $1_
, it tries to find a variable named 1_
that was captured like this (?P<1_>...)
which does not exist leading to the empty string.
So if you want to retain the use of indexes ($1
) while appending letters, digits, and underscores to the captured variable, you need to use the full syntax: ${1}_
:
f2 -f '(.*)\d.txt' -r '${1}_%02d{{ext}}'
┌──────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| ******************************** |
| test1.txt | test_01.txt | ok |
| test2.txt | test_02.txt | ok |
| test3.txt | test_03.txt | ok |
└──────────────────────────────────┘
I hope this explains it a bit. You can read the Expand docs to learn more.
I will also update the docs with the next release to mention this behaviour.
from f2.
Hi @ayoisaiah, thank you very much for the detailed answer, appreciate it!
Your solution works perfectly fine. Looking forward to the updated docs.
Have a great day and keep this project awesome :)
from f2.
Similarly there seems to be an issue with using capture groups directly in front of index variables.
> f2 -V -f '(.*)\d.txt' -r '$1%02d{{ext}}'
┌───────────────────────────────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| ********************************************************* |
| test1.txt | test%02d.txt | overwriting newly renamed path |
| test2.txt | test%02d.txt | overwriting newly renamed path |
| test3.txt | test%02d.txt | overwriting newly renamed path |
| test4.txt | test%02d.txt | overwriting newly renamed path |
└───────────────────────────────────────────────────────────┘
from f2.
Related Issues (20)
- Piping output to f2 doesn't work as expected HOT 1
- directories to lowercase not working HOT 4
- exiftool - fatal error: all goroutines are asleep - deadlock HOT 3
- Currently filenames like `EP.1.v0.1080p.mp4` do not get sorted correctly
- goldens testing integration HOT 1
- question: search and replace file contents HOT 5
- test data is missing ? HOT 2
- seemingly regex non-capturing group is not supported? HOT 5
- Installation and usage instructions for Termux/Android HOT 1
- x.cdt return None on some old image,exiftool shows DateTimeOriginal HOT 2
- [Help] How to match ISO date string HOT 1
- not working for me! HOT 4
- Fail to replace with RE HOT 3
- Data loss due to issue with --fix-conflicts HOT 6
- Cannot modify the file name of a file starting with '.' using .* matching? HOT 4
- [Question] Custom when fix conflicts HOT 1
- (Request) Making {%002d} more dynamically functional HOT 2
- Not working with basic regex? HOT 2
- Provide a GUI. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from f2.