View Single Post
  #101 (permalink)  
Old 03-27-10, 10:28
Sinndho Sinndho is online now
Registered User
 
Join Date: Mar 2009
Posts: 3,445
pkstormy,

I'm not sure that my RegEx example is worth an entry in the library, but here you are.

The project needs a reference to the Microsoft VBScript Regular Expressions 5.5. This library is part of Internet Explorer 5.5 (and later), so it should be available on all computers running Windows XP, Vista, or 7, as well as any computer with IE 5.5 or later installed (meaning almost every Windows PC that is used to connect to the Internet).

I've included five functions using regular expressions:

- RegExReplace works like the standard Replace function but with regular expressions in the Search parameter. That was the initial example I provided on the forum.

- RegExLike performs a comparison between a string and another that can contain a regular expression. It works a bit as the LIKE operator but LIKE can only evaluate a limited subset of regular expressions, so:
Code:
Panel = "ZB-E10-P522"
Debug.Print RegExLike(Panel, "\-P.*")
is very similar to:
Code:
Panel = "ZB-E10-P522"
Debug.Print Eval("'" & Panel & "' Like '*-P*'")
- RegExMatch returns True if one or more occurences of a sting that can contain a regular expression is found in another string, so:
Code:
Panel = "ZB-E10-P522"
Debug.Print RegExMatch(Panel, "\-P.*")
can be compared with:
Code:
Panel = "ZB-E10-P522"
Debug.Print Instr(Panel, "-P") <> 0
- RegExMatches returns the number of occurences a sting that can contain a regular expression is found in another string.

- RegExInStr is similar to the InStr function. It returns the position of the first occurence a sting that can contain a regular expression is found in another string.

All functions are not case-sensitive by default but an optional boolean parameter (IgnoreCase) can be set to False to make them case-sensitive.

These functions are just wrappers (black boxes?) hiding the different properties and methods of the RegExp class, and in most cases using an instance of that class is as easy as using them. Perhaps they are easier for someone that's not familiar with object-oriented programing and feels more at ease with "classical" functions.

Credits are due to the author of the site:
Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns
This is where the idea of using a reference to the RegExp class comes from.
Attached Files
File Type: zip RegEx.zip (13.5 KB, 40 views)
__________________
Have a nice day!
Reply With Quote