Incorrect extraction of the number of values. #2522
-
When getting values, the following occurs. $ echo 'foo(var1, var2, var3, var4, var5)' | rg '^foo((([^,]+,?){5}))' -r '$1' $ echo 'foo(var1, var2, var3, var4, var5)' | rg '^foo((([^,]+,?){4}))' -r '$1' $ echo 'foo(var1, var2, var3, var4, var5)' | rg '^foo((([^,]+,?){6}))' -r '$1' |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
It's correct. I believe you're misunderstand regex semantics here. A simpler example:
That is, ripgrep will prioritize a match over greediness. So that means a I believe what you want is to make sure you match a terminator:
|
Beta Was this translation helpful? Give feedback.
-
Could you please check the results? Perhaps I missed something important. $ echo 'foo(var1, var2, var3, var4, var5)' | rg '^foo((([^,]+(,|))){4}))' -r '$1' $ echo 'foo(var1, var2, var3, var4, var5)' | rg '^foo((([^,]+(,|))){6}))' -r '$1' |
Beta Was this translation helpful? Give feedback.
It's correct. I believe you're misunderstand regex semantics here. A simpler example:
That is, ripgrep will prioritize a match over greediness. So that means a
(re)+
can result in matching fewer repetitions ofre
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…