sharkdp / fd

A simple, fast and user-friendly alternative to 'find'
Apache License 2.0
34.29k stars 816 forks source link

[BUG] regex capture groups (backreferences are not supported) #1603

Open bedw8 opened 3 months ago

bedw8 commented 3 months ago

Checks

Describe the bug you encountered:

hi i wanted to find files named with a repeated pattern, like 1234567812345678.txt, for later rename them as 12345678.txt so i tried to find them with

fd '(\d{8})\1'

where \1 stands for the first regex capture group (\d{8}), but it fails with

[fd error]: regex parse error:
    (\d{8})\1
            ^^
error: backreferences are not supported

Note: You can use the '--fixed-strings' option to search for a literal string instead of a regular expression. Alternatively, you can also use the '--glob' option to match on a glob pattern.

I already find and renamed the files i wanted by just grep-ing the ls command, like

ls | grep -P '(\d{8})\1' > myfiles

and later running a for loop on each line of myfiles where a extract the group and rename the files with mv, but it would be nice to have this working on fd since its better for later renaming with command execution on the files. I think this feature would work great with https://github.com/sharkdp/fd/pull/1118 since all I did could have been replace with something like

fd '(\d{8})\1)' -x mv {} {1}.txt

PS: i'm not sure if this fit more as feature request than bug.

Describe what you expected to happen:

to list the wanted files as

ls | grep -P '(\d{8})(\1)' 

does

What version of fd are you using?

fd 10.1.0

Which operating system / distribution are you on?

NixOS/nixpkgs unstable
tmccombs commented 3 months ago

This is kind of a duplicate of #399

tavianator commented 3 months ago

See also https://crates.io/crates/fancy-regex