Skip to content

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

Open
@bedw8

Description

@bedw8

Checks

  • I have read the troubleshooting section and still think this is a bug.

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 #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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions