How to search with wildcards with RIPGREP

1.2k Views Asked by At

I am failing at using wildcards for words when using ripgrep to find content in my files. Any help welcome.

Specific case: looking for any word stargin with GHJA having any suffix such as GHJA129387 GHJA0938094, etc. (can be letters or numbers).

I tried with GHJA*, but did not work.

1

There are 1 best solutions below

0
On

You need to use regex with ripgrep, which uses some sort of perl compatible regex (with some caveats for complex cases not relevant to your case, as mentioned in the docs)

What you need:

rg 'GHJA.*?\b'

To explain,

  • .*? is the wildcard – the dot is the quantifier, so we can match any number of characters, the question mark makes the wildcard lazy, instead of greedy.
  • \b is a word boundary, which you should use because your wildcard is at the end of your search term.