Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegExp for Nested IF 1

Status
Not open for further replies.

jibberski

Programmer
Aug 24, 2005
52
US

Trying to setup pattern to return the outer If statement

Expression: IF(X=1,IF(y=2),1,0),0)*5/3
Returned should be: IF(X=1,IF(y=2),1,0),0)

Here's what I have for a pattern: (IF\()+(.)+\)

Thanks for your help!
 
Well, this pattern works for the test case that you presented:

IF\(.*\)

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 


Sorry a little misleading in my post. I'm trying to parse out the IF statements. Matching the parentheses. Is this possible?

Matches should be: IF(X=1,IF(y=2),1,0),0) and IF(y=2),1,0)

EBGreen thanks for the headstart !
 
Are you aware the innermost IF seems syntaxically incorrect ?
 

I am now !

Try two (this time straight cut and paste):

IF( Corner Trim? ,ROUNDTO(( # of outside corners +IF( Inside Corner Trim? , # of inside corners ,0))* Wall Height - Siding ,1,0),0)

 
I don't think you can do this with a straight Regex. I take that back, I don't think you can do it with a straight regex in VBSCript. I'm pretty sure that you could in a laguage that supports a richer regex syntax like Perl. What you are really looking for is a recursive parsing routine. I think you are probably going to need to roll your own unless you get lucky on google.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 

Using VBA in access 2003 with the VBScript engine checked on
so guess I'm rollin' my own

After some hard knocks to the head:

What about a replace string for IF to a function XX(,,)

How can I run a RegExp.Replace to fixup the
IF(.,.,.) to XX(".",".",".") for condition, true, false??


 
Again I'm not sure that you can do this through a single regex since you are really doing a few replacements. You essentially need to do these replacements:

IF becomes XX
( becomes ("
, becomes ","
) becomes ")

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top