Skip to content

Why does ripgrep fail to parse \[[^[]*\*[^[]*\] but tools like grep and ag don't? #2985

Answered by BurntSushi
limusch asked this question in Q&A
Discussion options

You must be logged in to vote

This is working as expected. Here's how to do what you want with ripgrep:

$ echo 'char stringbuf[12*128];' | rg '\[[^\[]*\*[^\[]*\]'
char stringbuf[12*128];
$ echo '"element[3]", val * len[3]' | rg '\[[^\[]*\*[^\[]*\]'
$

It is a non-goal for ripgrep to be compatible with grep.

ripgrep's regex engine tends to require escapes more than older regex dialects in an effort to improve error messages and reduce ambiguity. Moreover, ripgrep's regex engine supports nested character classes. For example:

$ echo 'δaΔ' | rg -o '[\pL--[a-z]]'
δ
Δ

Neither grep nor ag supports this. This is one of the many reasons ripgrep doesn't try to be a POSIX compatible grep.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@limusch
Comment options

Answer selected by BurntSushi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2984 on February 04, 2025 16:30.