f2 icon indicating copy to clipboard operation
f2 copied to clipboard

Fail to replace with RE

Open hellyguo opened this issue 1 year ago • 3 comments

version: F2 version v1.7.2, installed from apt system: Debian 12 bookworm

files:

00.a.txt
01.b.txt
02.c.txt
03.d.txt
04.e.txt
05.f.txt

cmd:

f2 -f "0(\d\)\." -r "0\$1_"

result:

+----------+--------+--------+
|  INPUT   | OUTPUT | STATUS |
+----------+--------+--------+
| 00.a.txt | 0a.txt | ok     |
| 01.b.txt | 0b.txt | ok     |
| 02.c.txt | 0c.txt | ok     |
| 03.d.txt | 0d.txt | ok     |
| 04.e.txt | 0e.txt | ok     |
| 05.f.txt | 0f.txt | ok     |
+----------+--------+--------+
 INFO  Use the -x or --exec flag to apply the above changes 

expected:

+----------+----------+--------+
|  INPUT   |  OUTPUT  | STATUS |
+----------+----------+--------+
| 00.a.txt | 00_a.txt | ok     |
| 01.b.txt | 01_b.txt | ok     |
| 02.c.txt | 02_c.txt | ok     |
| 03.d.txt | 03_d.txt | ok     |
| 04.e.txt | 04_e.txt | ok     |
| 05.f.txt | 05_f.txt | ok     |
+----------+--------+--------+
 INFO  Use the -x or --exec flag to apply the above changes 

hellyguo avatar Jul 10 '23 09:07 hellyguo

Hi @hellyguo ,

Thanks for reporting this. It's not a bug in F2 but due to the way Go interprets capture variables. You have to do this to get the correct result:

f2 -f "0(\d)\." -r '0${1}_'
┌──────────────────────────────┐
| ORIGINAL | RENAMED  | STATUS |
| **************************** |
| 00.a.txt | 00_a.txt | ok     |
| 01.b.txt | 01_b.txt | ok     |
| 02.c.txt | 02_c.txt | ok     |
| 03.d.txt | 03_d.txt | ok     |
| 04.e.txt | 04_e.txt | ok     |
| 05.f.txt | 05_f.txt | ok     |
└──────────────────────────────┘

I will keep this issue open so I remember to note this behaviour in the documentation.

ayoisaiah avatar Jul 10 '23 10:07 ayoisaiah

thx! I know now.

hellyguo avatar Jul 10 '23 11:07 hellyguo

sorry, I reopen again.

hellyguo avatar Jul 10 '23 11:07 hellyguo