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

Capturing group with lua replacement interpreter using ripgrep #320

Closed
alan910127 opened this issue Dec 5, 2024 · 3 comments
Closed

Capturing group with lua replacement interpreter using ripgrep #320

alan910127 opened this issue Dec 5, 2024 · 3 comments

Comments

@alan910127
Copy link

alan910127 commented Dec 5, 2024

Is it possible to deal with capturing groups with the lua replacement interpreter using ripgrep? I would like to do the following:

Search:

foo(bar)baz(.*)

Replace:

if groups[2] ~= nil and groups[2] ~= "" then
  return "yes: " .. groups[2]
else
  return "no 😢"
end
@MagicDuck
Copy link
Owner

@alan910127 This is available with astgrep (variable captures) and I would love to expose it for ripgrep, but it relies on rg --json output containing the capture group text, which is currently not available.

Also, mind you I've tried before to add a PR to ripgrep for a different issue (diff support, which we hack around for in this plugin) and it's been sitting there unreviewed since September 😢.
BurntSushi/ripgrep#2883
Not blaming the owner since this is after all free work that he provides to the community, but not sure how much luck you would have adding the capture group text in the output...

@alan910127
Copy link
Author

alan910127 commented Dec 6, 2024

@MagicDuck Thanks for your clarification! I'm sorry to hear about the PR situation. It seems like BurntSushi (the author) has shifted focus to other projects. I hope your PR gets reviewed soon!

@MagicDuck
Copy link
Owner

Closing this issue for now but like I said I am always open to adding the functionality if the capture groups become available on the ripgrep output at some point.

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

No branches or pull requests

2 participants