Codebox Software

RegEx DLL

Published:

RegEx.DLL provides some much needed regular-expression handling for VB programmers. The 'clsRegEx' class implements all the common UNIX wildcard characters allowing sophisticated string comparisons and search-and-replace operations to be performed.

  • The '*' character represents zero or more occurrences of the previous character in the expression:
    ab*c matches ac, abc, abbc, abbbbbbbc ...
  • The '+' character represents one or more occurrences of the previous character in the expression:
    ab+c matches abc, abbc, abbbbbbbc but not ac
  • Numbers within curly brackets represent a specific number of occurrences of the previous character:
    a{3} matches aaa a{3,5} matches aaa, aaaa and aaaaa
  • The '?' character represents zero or one occurrences of the previous character:
    a?c matches ac and aac
  • The '.' character represents any single character:
    a.c matches abc, aXc but not ac or abbc

Round brackets can be used to apply multipliers, such as '*' or '+', to groups of characters:

  • (abc)* matches an empty string, abc, abcabc, abcabcabc ...
  • (abc)+ matches abc, abcabc, abcabcabc ...
  • (a.c)* matches an empty string, abc, abcaXc, aXcaYcaZc ...

Square brackets can be used to specify possible values for a single character. A hyphen can be used in this context to represent a range of characters. If the first character within the brackets is a '^' then the range is exclusive rather than inclusive (ie. the expression matches any single character not shown):

  • a[bB]c matches abc and aBc
  • a[0-9]c matches a0c, a1c, a2c ... a9c
  • a[^0-9]c matches abc and aXc but not a0c ... a9c

A '\' symbol negates the special meaning of the following character. Only valid if it precedes one of *+?\{([])}.

  • a\*c matches a*c
  • a[\[\]]c matches a]c and a[c
  • a\\c matches a\c
  • >ab\c is not a valid expression

The download includes VB code samples demonstrating how to use the library.