Skip to content

Incorrect extraction of the number of values. #2522

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

You must be logged in to vote

It's correct. I believe you're misunderstand regex semantics here. A simpler example:

$ echo 'aaaaa' | rg '(a+){2}'
aaaaa
$ echo 'aaaaa' | rg '(a+){3}'
aaaaa
$ echo 'aaaaa' | rg '(a+){4}'
aaaaa
$ echo 'aaaaa' | rg '(a+){5}'
aaaaa
$ echo 'aaaaa' | rg '(a+){6}'
$

That is, ripgrep will prioritize a match over greediness. So that means a (re)+ can result in matching fewer repetitions of re if it means an overall match could be found. In your regex, ^foo((([^,]+,?){9})), it might be helpful to focus on the thing being repeated: [^,]+,?. Notice that that regex can match any single letter except for , since the , at the end is made optional by ?.

I believe what you want is to make sure you matc…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by BurntSushi
Comment options

You must be logged in to vote
2 replies
@BurntSushi
Comment options

@BurntSushi
Comment options

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