I'm trying to write a regular expression to match the input of complex number in the following forms: (With a,b real number, and i/I imaginay unit)
a
a+bi
a-bi
+bi
-bi
a+i
a-i
i
-i
Of course in all numbers I want to be able to also read exponential form (eg: 1.23e+45-67.89e-1256i). I've come up with this:
regex aplusbi ("(([\\+-]?[\\d]+([\\.][\\d]+)?)?([eE][\\+-]?[\\d]+)?)?(([\\+-])?(([\\d]+?([\\.][\\d]+)?)?([eE]?[\\+-]?[\\d]+)?)?[iI])?")
It gets most of them correct, however when I input +bi or -bi or simply bi the b part goes into the real one, and it also recognises this number as correct:
12.418.546i
getting 12.41 into the real part and 8.546 into the imaginary one. How could I correct it? I'm kind of new to C++ and regexes so any kind of help would be appreciated, thanks!