I would like to create a regex which will allow me to add spaces around assignment operators in C++ code (as I prefer this style), e.g. so that
x=something
becomes
x = something
but
if(y==x)
does not become
if(y = = x)
and so on including !=,<=,>=
I am relatively new to regular expressions and have tried the following:
(?<![\s=])(=)(?!=)
I thought this would be a good starter, but this does not seem to match. Could someone explain what I have not understood about regex here?
Edit
Example using regex which does not match in Code::Blocks IDE

Try something like this:
(?<![<>=!])\s*=\s*(?!=)replaced with=.OR
([^<>=!])\s*=\s*([^=])replaced with\1 = \2Both lookaround assertions are needed since the pattern is not anchored.
Your own regex was, in reality, just missing
<>in the character class. I have improved on it a tiny bit, look at the demo.Demo+explanation for first regex: http://regex101.com/r/kU1hP2
Demo+explanation for second regex: http://regex101.com/r/lK1oQ3
Note:
\smatches whitespace!