Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support PCRE (look behind) #399

Closed
ar1a opened this issue Jan 26, 2019 · 9 comments
Closed

Support PCRE (look behind) #399

ar1a opened this issue Jan 26, 2019 · 9 comments
Labels

Comments

@ar1a
Copy link

ar1a commented Jan 26, 2019

with the addition of --pcre2 flag into BurntSushi/ripgrep , lookbehind is something i've been pining for. It'd be great if PCRE2 support could be added

@sharkdp
Copy link
Owner

sharkdp commented Feb 9, 2019

Thank you for the feedback.

Could you please provide a few examples where advanced regex features like lookbehind could be useful in a realistic fd use case?

@ar1a
Copy link
Author

ar1a commented Feb 10, 2019

I can't think of any examples off the top of my head but the use case I was going for was the negative lookaheads/behinds. They are pretty awkward to express without lookbehinds.

@sharkdp
Copy link
Owner

sharkdp commented Feb 13, 2019

I think I am going to have to decline (for now).

fd is trying to stay simple and is only targeting "80% of the use cases" (see README), so I am not going to implement a feature without any use case at all.

@sharkdp sharkdp closed this as completed Feb 13, 2019
@jrraymond
Copy link

A use case is finding all file which don't match an extension, ei: ^.+\.(?!py$)[^.]+$. ?! requires look-around.

@sharkdp
Copy link
Owner

sharkdp commented Mar 6, 2020

@jrraymond

This use case can also be solved with fds -E, --exclude <pattern>... option:

fd pattern -E '*.py'

For example: search for all files matching the README pattern that do not have an md extension:

fd README -E '*.md'

That's (arguably) also more readable than the lookbehind.

@ouxch
Copy link

ouxch commented Mar 30, 2022

@sharkdp
a use case is to find out files with both 'mutation' and 'asset' in their names
option: ^(?=.*mutation)(?=.*asset).*$

@unusualevent
Copy link

the -E exclude thing definitely slipped past me on the first few tries to solve this. Compared to wishing I had a negative lookbehind... having a quick "exclude" glob seems so much nicer. it's possible this could be phrased better in the readme as "find all files not matching x" is a use case of it, not just "ignore" :)

@sharkdp
Copy link
Owner

sharkdp commented Jun 14, 2023

@unusualevent A small PR with a documentation update would be very much appreciated.

@unusualevent
Copy link

@sharkdp I'd probably butcher the readme :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants