xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

Wild2RegEx()

Converts a character string including wild card characters to a regular expression.

Syntax

Wild2RegEx( <cWildCard> [,<lCaseSensitive>] ) --> cRegEx

Arguments

<cWildCard>
This is the character string holding wild card characters ("*" and/or "?").
<lCaseSensitive>
This parameter defaults to .F. (false) so that a case insensitive regular expression is produced. Passing .T. (true) results in a case sensitive regular expression.

Return

The function returns a character string holding the regular expression which is equivalent to the wild card string.

Info

See also:HB_AtX(), HB_RegEx(), HB_RegExAll(), HB_RegExComp(), HB_RegExSplit()
Category: Character functions , Regular expressions , xHarbour extensions
Source:rtl\regex.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example translates a file mask to a regular expression and
// matches it with file names stored in an array.

   PROCEDURE Main
      LOCAL aFiles := { "Customer.dbf", ;
                        "Customer.dbt", ;
                        "Custom01.ntx", ;
                        "Custom02.ntx", ;
                        "Custom03.ntx", ;
                        "Customer01.dbf"}

      LOCAL cFileMask := "CUSTOM??.*"
      LOCAL cRegEx    := Wild2RegEx( cFileMask )
      LOCAL cFile, cFound

      ? "Wild card:", cFileMask
      ? "RegEx    :", cRegex
      ?
      FOR EACH cFile IN aFiles
         cFound := HB_AtX( cRegEx, cFile )

         ? "Matching:", cFile
         IF cFound == NIL
            ?? " no match"
         ELSE
            ?? " OK"
         ENDIF
      NEXT
      ** Output:
      // Wild card: CUSTOM??.*
      // RegEx    : (?i)\bCUSTOM.?.?\..*\b
      //
      // Matching: Customer.dbf OK
      // Matching: Customer.dbt OK
      // Matching: Custom01.ntx OK
      // Matching: Custom02.ntx OK
      // Matching: Custom03.ntx OK
      // Matching: Customer01.dbf no match
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe