The reason why this does not work is [^!<>=]=
, which makes your code look for a character which is not =
followed by a character which is =
. I can see your intention in doing so, but it's the wrong way.
For the simple, case have a look at the following expression:
[0-9A-Za-z_]+\s*=\s*[0-9A-Za-z_]+(\(\s*[0-9A-Za-z_]*\s*\))?
This matches the c=getc(pp)
part of your source, because it looks for a =
which is either followed (or preceded) by optional whitespaces and characters or numbers. Already this prevents the regex from matching ==
, <=
, !=
, or >=
.
Aside of that it also looks if the right hand side is a function or simply a variable or just a number (optional match through ?
for the bracket-part at the end of the expression). Note also the *
for the matching part within the braces ([0-9A-Za-z_]*
), which enables you to match function calls without parameters.
Works for:
(c=getc(p)) == EOF
(c =getc()) == EOF
(c=getc( )) == EOF
(c = getc( p )) == EOF
(c = i) == EOF
(c=10) == EOF
This will not work for constructs, such as x = y(z())
(and surely many more).
Aside of this being said, I recommend the following link (not exactly your question, but really nice insights):
Regular expression to recognize variable declarations in C