Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
1 task done
bedw8 opened this issue Aug 9, 2024 · 2 comments · May be fixed by #1606
Open
1 task done

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

bedw8 opened this issue Aug 9, 2024 · 2 comments · May be fixed by #1606

Comments

@bedw8
Copy link

bedw8 commented Aug 9, 2024

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
@bedw8 bedw8 added the bug label Aug 9, 2024
@tmccombs tmccombs linked a pull request Aug 13, 2024 that will close this issue
@tmccombs
Copy link
Collaborator

This is kind of a duplicate of #399

@tavianator
Copy link
Collaborator

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants