Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi...

I need somewone pretty good dealing with RegEx.

 

I need to buid a RegEx expression to validate math operators that aren't 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 it'll be geatlly appretiated...

 

Thank you very much.

Alex :p

Software bugs are impossible to detect by anybody except the end user.
  • 1 month later...
Posted

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"...)... you'll have to write it like this :

@"(\(|\)" which mean... capture "(" or ")".

 

So... I don't 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.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...