rg 'warn|error' logs/Alternation is often the fastest way to combine related searches into one pass.
Use basic regex, PCRE2, word boundaries, alternation, and literal searches with ripgrep.
Common regex patterns that appear in real code and logs.
rg 'warn|error' logs/Alternation is often the fastest way to combine related searches into one pass.
rg '\bselect\b' docs/Word boundaries are essential when searching SQL, config keys, or language keywords.
rg '\b\d{3}\b' .Handy for HTTP status codes, IDs, and validation rules.
rg '(GET|POST|PUT|DELETE) /api/' server.logEven when not replacing, capture groups make complex patterns easier to reason about.
rg -v '^#' .env.exampleGreat for removing comments or blank-line noise in quick inspections.
Search literal text when regex behavior would be inconvenient or misleading.
rg -F 'user.name' .Use `-F` when searching strings that contain dots, brackets, or other regex metacharacters.
rg -F -e 'panic!' -e 'unwrap()' src/Useful for audits where you want one combined pass over the repository.
rg 'config\.json' .This is handy when you want regex power overall but still need to match punctuation literally.
Match text spanning lines using a more powerful regex engine.
rg -Pzo 'BEGIN.*?END' notes.txtUse PCRE2 plus multiline/null-data modes when the default engine's line-oriented behavior is too strict.
rg -F -f patterns.txt src/Great for deny lists, migration checklists, or curated audit terms.
Enable features beyond ripgrep's default regex engine when needed.
rg -P '(?<=Authorization: )Bearer\s+\S+' headers.txtPCRE2 is especially useful for look-behind, backreferences, and some complex matching scenarios.
rg -P '\b(\w+)\s+\1\b' notes.txtBackreferences are not supported by the default regex engine, so `-P` is required.
rg -P 'token(?==)' .envLook-ahead helps when you want to match a token without consuming surrounding syntax.
rg '\p{L}+' docs/Useful for multilingual repos and documentation sets.
rg -U 'foo
bar' sample.txt`-U` disables the line-based restriction so patterns can span lines; combine with care because it can increase work and output size.