Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old October 8th 08, 04:46 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jun 2006
Posts: 55
Default Regular Expression Conditionals (?(if)then|else) in VBA?

Does the VBScript_RegExp_55.RegExp object support conditionals?

According to http://www.regular-expressions.info/refflavors.html .NET allows
for conditionals using the (?(if)then|else) structure, and I thought that the
VBScript RegExp object used the .NET flavor of RegEx. But when I try to use
it, the object returns an error message.

When I try to do the following:
objRegExp.Pattern = “^(<)?test(?(1)|)$”
I get the following error message:
Method 'Test' of object 'IRegExp2' failed

I am trying to use RegEx conditionals to ensure that a string with an
opening bracket has a closing bracket. So the RegEx above would accept “test”
or “<test”, but it would not accept “<test” or “test”.

I have looked all over for documentation on the VBScript=RegExp_55.RegExp
flavor of RegEx, but have had little success.

Any help would be greatly appreciated.

Thank you.

  #2   Report Post  
Old October 8th 08, 05:32 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jun 2006
Posts: 55
Default Regular Expression Conditionals (?(if)then|else) in VBA?

http://msdn.microsoft.com/en-us/libr...1x(VS.85).aspx

That's a link to the Regular Expression Syntax for VBScript. It appears that
conditionals are not supported.

Too bad. That would have been incredibly useful.
  #3   Report Post  
Old October 8th 08, 06:43 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 5,651
Default Regular Expression Conditionals (?(if)then|else) in VBA?

On Wed, 8 Oct 2008 08:46:31 -0700, Lazzaroni
wrote:

Does the VBScript_RegExp_55.RegExp object support conditionals?

According to http://www.regular-expressions.info/refflavors.html .NET allows
for conditionals using the (?(if)then|else) structure, and I thought that the
VBScript RegExp object used the .NET flavor of RegEx. But when I try to use
it, the object returns an error message.

When I try to do the following:
objRegExp.Pattern = ^(<)?test(?(1)|)$
I get the following error message:
Method 'Test' of object 'IRegExp2' failed

I am trying to use RegEx conditionals to ensure that a string with an
opening bracket has a closing bracket. So the RegEx above would accept test
or <test, but it would not accept <test or test.

I have looked all over for documentation on the VBScript=RegExp_55.RegExp
flavor of RegEx, but have had little success.

Any help would be greatly appreciated.

Thank you.


The VBScript regex object uses the Javascript flavor.
--ron
  #4   Report Post  
Old October 8th 08, 06:50 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Aug 2008
Posts: 5,934
Default Regular Expression Conditionals (?(if)then|else) in VBA?

Without using regular expressions, does this do what you want?

If Variable Like "[!<]*[!]" or Variable Like "<*" Then

--
Rick (MVP - Excel)


"Lazzaroni" wrote in message
...
Does the VBScript_RegExp_55.RegExp object support conditionals?

According to http://www.regular-expressions.info/refflavors.html .NET
allows
for conditionals using the (?(if)then|else) structure, and I thought that
the
VBScript RegExp object used the .NET flavor of RegEx. But when I try to
use
it, the object returns an error message.

When I try to do the following:
objRegExp.Pattern = “^(<)?test(?(1)|)$”
I get the following error message:
Method 'Test' of object 'IRegExp2' failed

I am trying to use RegEx conditionals to ensure that a string with an
opening bracket has a closing bracket. So the RegEx above would accept
“test”
or “<test”, but it would not accept “<test” or “test”.

I have looked all over for documentation on the VBScript=RegExp_55.RegExp
flavor of RegEx, but have had little success.

Any help would be greatly appreciated.

Thank you.


  #5   Report Post  
Old October 8th 08, 08:06 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jun 2006
Posts: 55
Default Regular Expression Conditionals (?(if)then|else) in VBA?

Rick:

That is correct, but within a larger string. I am looking for unclosed
brackets using a data validation application that uses rules written in
RegEx. It checks the contents of cells in Excel, based on a unique column
identifier.

Thanks.

Thomas


  #6   Report Post  
Old October 8th 08, 08:09 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jun 2006
Posts: 55
Default Regular Expression Conditionals (?(if)then|else) in VBA?

Ron:

Too bad it doesn't use the .NET flavor, which is much more robust.

Thanks.
  #7   Report Post  
Old October 8th 08, 08:22 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Aug 2008
Posts: 5,934
Default Regular Expression Conditionals (?(if)then|else) in VBA?

Okay, but if I understand your larger goal (checking to ensure multiple
left/right brackets in a text string are paired), this (again, non-RegEx)
code might work for you...

If UBound(Split(Variable, "<")) = UBound(Split(Variable, "")) And _
Not Variable Like "*<[!]<*" And Not Variable Like "*<[!]<*" Then

--
Rick (MVP - Excel)


"Lazzaroni" wrote in message
...
Rick:

That is correct, but within a larger string. I am looking for unclosed
brackets using a data validation application that uses rules written in
RegEx. It checks the contents of cells in Excel, based on a unique column
identifier.

Thanks.

Thomas


  #8   Report Post  
Old October 8th 08, 09:53 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 5,651
Default Regular Expression Conditionals (?(if)then|else) in VBA?

On Wed, 8 Oct 2008 12:09:02 -0700, Lazzaroni
wrote:

Ron:

Too bad it doesn't use the .NET flavor, which is much more robust.

Thanks.


I'm not sure exactly what you want to do, but

"<test|(^|[^<])test(?!)"

might match what you wrote for a specific string, so long as it doesn't include
embedded delimiters.

--ron


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can someone help me with this regular expression? [email protected] Excel Discussion (Misc queries) 3 March 10th 09 07:36 PM
Help with regular expression PO Excel Programming 3 May 2nd 07 01:39 PM
Regular Expression sl Excel Discussion (Misc queries) 2 January 23rd 07 11:57 PM
Regular Expression for cell address M. Authement Excel Programming 11 January 4th 07 08:57 PM
Regular expression searching problem LarryLev Excel Programming 0 September 15th 05 07:44 PM


All times are GMT +1. The time now is 10:35 AM.

Powered by vBulletin® Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2004-2019 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"

 

Copyright © 2017