The first problem with your regex is that your forgot to escape the brackets :).
Inside the brackets, you are just matching .*, which is everything except line endings, which doesn't seem to be what you want.
From your example, I would guess that you want to match those if statements where there is no trailing or leading commas just hanging there. So inside the brackets, this regex should match:
\w+\s*(?:\s*,\s*\w+)*
Explanation:
If we remove all the \s* (they are just there to allow whitespace everywhere), we get
\w+(?:,\w+)*
Basically, word characters, followed by a bunch of "comma and word characters" thingys. This ensures no comma at the end or the start because the end and start of the pattern are both \w.
We can just substitute that into your original regex:
(if|while)\s*\(\w+\s*(?:\s*,\s*\w+)*\)\s*\{.*