xHarbour Reference Documentation > Function Reference |
Converts a character string including wild card characters to a regular expression.
Wild2RegEx( <cWildCard> [,<lCaseSensitive>] ) --> cRegEx
The function returns a character string holding the regular expression which is equivalent to the wild card string.
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 |
// 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
http://www.xHarbour.com