Function String Extras Class

EgrepOrStringsToRegexPattern

"UNIX egrep Or Strings To Regular Expression Pattern" Create a Find pattern that will search for any of several words using a single Find command within Microsoft products like Visual Basic, Access, etc. Convert a UNIX "egrep" (extended global regular expression) like "or" string expression into a pattern recognized by the Microsoft's Find command.

Signature (Visual Basic / VBA)

Public Function EgrepOrStringsToRegexPattern( _
      ByVal vOrStrings As Variant _
    , Optional ByVal vSeparator As Variant _
    ) As Variant

Code Example

    EgrepOrStringsToRegexPattern("If|On") = "[IO][fn]"
    EgrepOrStringsToRegexPattern("Unique|Dups") = "[UD][nu][ip][qs]"

Parameters

Parameter Description
vOrStrings String containing the list or words (or phrases) each separated by the string vSeparator. Function returns Null if vOrStrings is Null or cannot be fixed up to a String.
vSeparator The string which separates the words (or phrases) within string vOrStrings. vSeparator defaults to the vertical-bar character (|) if it is missing or Null or cannot be fixed up to a String.

Notes & Version History

Details This function will create an expression that, with Pattern Matching enabled, can be used to locate occurrences of more than one word using a single Find command within Microsoft products like Visual Basic, Access, etc. Function interprets a string "Unique|Dups" as a pattern that will match text containing either "Unique" or "Dups".
Note Function creates a string expression which uses character classes to find the words. Because of this imperfect translation of the "or" expression, the search may find some matches which do not represent any of the original words. For example, a vOrStrings of "If|On" would translate to "[IO][fn]", and when used with the Find command, that pattern would find all occurrences of the string "If", "In", "On", and "Of".
Note Function uses Binary comparisons to locate the separator string vSeparator within the string vOrStrings.