Parsing a complex number using regular expressions
Both of your solutions are wrong, in different ways.  Yours is worse, though, because it fails in a way that can actually succeed in giving completely wrong answers.

Your solution

Your technique is, as your professor noted, sloppy.  It falls apart in several cases that I would consider reasonable inputs:


Pure imaginary numbers such as "5i"
No imaginary component, such as "1"
No imaginary coefficient, such as "5+i"
Imaginary number with a space, such as "3 - 3i"
Decimals more precise than one-tenth, such as "3.14"


Furthermore, using an ArrayList seems extravagant.  You shouldn't need one.

Professor's solution1

Sanitizing the input by discarding spaces — is that a good idea?  Why?  Is there another way to handle spaces?

Why three Patterns, three Matchers, and three .find()s?  Can it be done with fewer?

Within each pattern, is your regex more correct, or his?  Can you spot any bugs in his character classes (i.e. the stuff inside [square brackets])?

Are there any inputs that also fail with his code?  Does his code accept any inputs that should be considered invalid?



1 We shouldn't really be criticizing code that you didn't write, so I'll give you some questions to ponder instead.