This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

I have the following pattern that matches string expressions not enclosed in () starting at the beginning of the string:

**^[^(]*?((((-?\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>)?)))[^)]*$

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) No Match

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

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

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

The following are some 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

I had prior assistance on this but I failed to realize that the examples I gave did not cover all the possible combinations. I think I've got them covered now. Any advice is welcome.

examples:

(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*

(2m*5/2z*p/3n)-6m/3m+2x/3m

(2m*5/2z*p/3n)-6m/3m+2x/3m

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

The following are some examples:

(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*

(2m*5/2z*p/3n)-6m/3m+2x/3m

(2m*5/2z*p/3n)-6m/3m+2x/3m

I had prior assistance on this but I failed to realize that the examples I gave did not cover all the possible combinations. I think I've got them covered now. Any advice is welcome.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

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.

If need be I can simplify my needs to just identifying the stings where all or part of the expressions are not inside (). Then I can use code to process the string. example:

(2x/3m) No Match

2x/3m Match

2x/3m*45*h Match

(2m*5/2z*p/3n) No Match

6m/3m+2x/3m*45*h-(2m*5/2z*

(2m*5/2z*p/3n)-6m/3m+2x/3m

(2m*5/2z*p/3n)-6m/3m+2x/3m

(2x/3m) (2x/3m)

2x/3m No Match

2x/3m*45*h No Match (2m*5/2z*p/3n) (2m*5/2z*p/3n)

6m/3m+2x/3m*45*h-(2m*5/2z*

(2m*5/2z*p/3n)-6m/3m+2x/3m

(2m*5/2z*p/3n)-6m/3m+2x/3m

you now have a regex expression which is in no way verifiable and where you easily found some sample expressions where it doesn't work as expected. you would have the same situation if someone found a regex expression which would match correctly for the additional patterns you posted, but probably not the one ste5an has posted. so, you end with an overkill regex expression where you never will know whether it would fail or succeed.

in my opinion, regex is not suitable for to parse mathematical expressions of a non-trivial complexity.

math expressions normally were parsed by recursively dividing expressions into sub expressions and build an array of operations which contain of two operands and one operator.

for example the expression

p/3n-(6m/3m+2x)/3m*45

would be parsed to

```
1: p 3n /
2: 6m 3m /
3: @2 2x +
4: @3 3m /
5: @4 45 *
6: @1 @5 -
```

where @x points to the x-th element of the array. with the array and known input parameters the expression easily could be calculated. it also could be turned back to a string expression which has all parentheses:

(p/3n-((((6m/3m)+2x)/3m)*4

Sara

Thanks, you are absolutely right it was overkill and overly complicated. I did however find a solution.

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 trialUsing your procedure, your

My

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.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.