Somehone good on Regular Expressions (RegEx) ??

AlexCode

Well-known member
Joined
Jul 7, 2003
Messages
931
Location
Portugal
Hi...
I need somewone pretty good dealing with RegEx.

I need to buid a RegEx expression to validate math operators that arent within parenthesis.

By math operator I mean +,-,* and /

Sample matches:
2+3 >Matches 1 (easy)
2+(2-3) >Matches 1
(#RentCP*2)/4 >Matches 1 (the / operator)
(#A/2)+#B*(A-2) >Matches 2 (the + and * operators)
(2*(A+2))/3 >Matches 1 (the / operator)
-(B+4)*3 >Matches 2 (the - and * operators)

Sample non matches:
(2+3)
(2*(A+2))

As you may already fugured out, this is to work with math expressions.

If somewone wants to put his RegEx skills on this itll be geatlly appretiated...

Thank you very much.
Alex :p
 
hummm... a good one...

@"[+-*/]" that is to dertermine the operator...
.* = Any character (not a lazy match)
.*? = Any character (lazy match... it means that it match the first in the Left-Right order unless you specified the RegexOptions Right to Left)

to specify parenthesis (that are "Regex operator"...)... youll have to write it like this :
@"(\(|\)" which mean... capture "(" or ")".

So... I dont know really how to do that... I just began putting myself to it... but if you have some question... maybe we could work this problem together.
 
Back
Top