I'd like to search for a pattern in both file name and content. Ideally at the same time. Is this possible, if not is there a recommended workaround?
No. ripgrep doesn't even expose a way to search file paths with a regex at all. The only way to match on file paths is with globs. If you want regexes, you need to use pipelines, e.g., rg --files | rg 'foo\w+'.
I don't think I can suggest a work around because the desired semantics aren't clear. What problem are you trying to solve? What is your input? What's your desired output?
If you want regexes, you need to use pipelines, e.g.,
rg --files | rg 'foo\w+'.
I'm using ripgrep to implement file search in my app. I want the search results to include files if name OR content matches the pattern.
I can use your suggestion to solve the problem, I just wanted to make sure I wasn't missing a more direct built in solution.
Thanks!
@jessegrosjean @BurntSushi What if I want the search results to include files if name AND content matches the pattern?
@zachliu rg content-pattern | rg file-pattern will get you pretty close. Or just do rg -g 'file-glob-pattern' content-pattern.
@BurntSushi many thanks :+1:
Most helpful comment
@zachliu
rg content-pattern | rg file-patternwill get you pretty close. Or just dorg -g 'file-glob-pattern' content-pattern.