Problems modifying a pattern to not match when certain characters are present before and after a string.

I have the following regex that matches polynomials.  (eg.. (2x/3m), 2x/3m, 2x/3m*45*h, (2m+5-2z*p/3n)).
(?<!\()((((-?\d+(?:\.\d*)?)(<sup>(-?\d+)</sup>)?(<sup>E[-+]\d+</sup>)?(-?[a-z]((<sup>-?\d+</sup>)|(<sup>E[-+]\d+</sup>)?))?|(-?[a-z]((<sup>-?\d+</sup>)|(<sup>E[-+]\d+</sup>)?)))[*|/|+|-])+)(?!\*\/)((-?\d+(?:\.\d*)?)(<sup>(-?\d+)</sup>)?(<sup>E[-+]\d+</sup>)?(-?[a-z]((<sup>-?\d+</sup>)|(<sup>E[-+]\d+</sup>)?))?|(-?[a-z]((<sup>-?\d+</sup>)|(<sup>E[-+]\d+</sup>)?)))(?!\))

Open in new window

It matches all expressions weather they are enclosed in parenthesis or not.
pPolynomial                          Match Found
(2x/3m)                                            2x/3m
2x/3m                                              2x/3m
2x/3m*45*h                                   2x/3m*45*h
(2m+5-2z*p/3n)                             2m+5-2z*p/3n

I want to modify it so that it only matches expressions not enclosed in parenthesis.
Polynomial                          Match Found
(2x/3m)                                            no match
2x/3m                                              2x/3m
2x/3m*45*h                                   2x/3m*45*h
(2m+5-2z*p/3n)                             no match

I attempted to do a negative look behind (?<!\() and a negative look ahead (?!\)) but when I did the following happened.
Polynomial                          Match Found
(2x/3m)                                            x/3
2x/3m                                              2x/3m
2x/3m*45*h                                   2x/3m*45*h
(2m+5-2z*p/3n)                             m+5-2z*p/3

Could someone please help me out with this?
NevSoFlyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
^[^(]*?((((-?\d+(?:\.\d*)?)(<sup>(-?\d+)</sup>)?(<sup>E[-+]\d+</sup>)?(-?[a-z]((<sup>-?\d+</sup>)|(<sup>E[-+]\d+</sup>)?))?|(-?[a-z]((<sup>-?\d+</sup>)|(<sup>E[-+]\d+</sup>)?)))[*|/|+|-])+)(?!\*\/)((-?\d+(?:\.\d*)?)(<sup>(-?\d+)</sup>)?(<sup>E[-+]\d+</sup>)?(-?[a-z]((<sup>-?\d+</sup>)|(<sup>E[-+]\d+</sup>)?))?|(-?[a-z]((<sup>-?\d+</sup>)|(<sup>E[-+]\d+</sup>)?)))[^)]*$
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NevSoFlyAuthor Commented:
Thank you.  You answered the question that I had asked.  Unfortunately after testing your solution I realized that there were instances that I did not originally think of and my question and examples were incomplete.  

What I actually need is a pattern that matches the first part of a string expression that is not enclosed in ()

The following are some but may not be all examples:

String Expressions                                                                           Matches
(2x/3m)                                                                                              No Match
2x/3m                                                                                                2x/3m
2x/3m*45*h                                                                                     2x/3m*45*h
(2m*5/2z*p/3n)                                                                               No Match
6m/3m+2x/3m*45*h-(2m*5/2z*p/3n)                                        6m/3m+2x/3m*45*h
(2m*5/2z*p/3n)-6m/3m+2x/3m*45*h                                        -6m/3m+2x/3m*45*h
(2m*5/2z*p/3n)-6m/3m+2x/3m*45*h(2m*5/2z*p/3n)            -6m/3m+2x/3m*45*h

If you like I can post another similarly titled question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.