Giter Site home page Giter Site logo

Comments (4)

ayoisaiah avatar ayoisaiah commented on September 22, 2024 1

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.

ayoisaiah avatar ayoisaiah commented on September 22, 2024 1

@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.

d-Rickyy-b avatar d-Rickyy-b commented on September 22, 2024 1

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.

d-Rickyy-b avatar d-Rickyy-b commented on September 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.