<-- Previous || Up || Next -->

Grep To Like Function
String Manipulations Class

Public Function GrepToLike( _
    ByVal vPattern As Variant _
    ) As Variant

"UNIX grep To Visual Basic LIKE"
Fixes up some limited forms of wildcards from one style (UNIX) to another (Microsoft).
Accepts a wildcard that is more like those recognized by UNIX and returns the corresponding wildcard/pattern recognized by the Microsoft's LIKE operator.

Summary: Make minor modifications to the patterns recognized by the Visual Basic LIKE operator to make them more like the regular expressions as defined under UNIX. Patterns are normally changed so that they are not anchored to the beginning and end of the string to be searched. A leading caret anchors the match to the beginning of he search string, and a trailing dollar sign anchors the match to the end of the search string. Either of these interpretations can be overridden by preceding the characters with a backslash. In addition, leading and/or trailing backslashes must also be preceded by a backslash.
Examples:
    GrepToLike("Washington") = "*Washington*"
    GrepToLike("^Washington") = "Washington*"
    GrepToLike("^Washington$") = "Washington"
    GrepToLike("\^Washington\$") = "*^Washington$*"
    GrepToLike("\\Washington\$") = "*\Washington$*"
    GrepToLike("\\Washington\\") = "*\Washington\\*"
    GrepToLike("Wash\ing\ton") = "*Wash\ing\ton*"
See also:
    EgrepOrStringsToRegexPattern Function
    Like Operator (Visual Basic)
    grep Program (UNIX)
    regular expressions (UNIX)
vPattern: The UNIX-like regular expression which is to be converted into a corresponding LIKE operator pattern. Function returns Null if vPattern is Null or cannot be fixed up to a String.

Ignore leading backslash character and interpret next character literally.

When caret found at beginning of string: anchor to beginning of line.

Ignore trailing backslash dollar-sign characters, interpreting the dollar sign literally.

When dollar-sign found at end of string: anchor to end of line.

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.