Ripgrep: Is it possible to search file names and content at same time with same regex?

Created on 4 Aug 2018  路  5Comments  路  Source: BurntSushi/ripgrep

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?

question

Most helpful comment

@zachliu rg content-pattern | rg file-pattern will get you pretty close. Or just do rg -g 'file-glob-pattern' content-pattern.

All 5 comments

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:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hauleth picture hauleth  路  3Comments

kenorb picture kenorb  路  3Comments

timotheecour picture timotheecour  路  3Comments

daxim picture daxim  路  3Comments

andschwa picture andschwa  路  3Comments