Fixed regex logic problem with equations