Just the beginningIn an earlier blog entry I unveiled a new FLL for Visual FoxPro that would allow Visual FoxPro developers to use Regular Expressions for matching. That FLL, while very useful if you are competent with regular expressions, was just the start of what's possible. Now that I have a basic library that exposes part of the functionality of Boost Regex, I can expand it to include additional functionality. I believe you'll find the additions, which include formatting and splitting useful.
Download the regexp.fll (61 KB approx)
regexp.fll Documentation...
Function REGEXP()
Signature: RegExp(cString, cRegularExpression [, nFunctionType[, cFormatExpression | cArrayName]])
Parameters:
cStringtoEncrypt - The string to be searched, formatted, or split
cRegularExpression - A regular expression using Perl syntax. Additional documention.
nFunctionType - There are currently 3 function types available. The value of this parameter determines the operation that RegExp will perform as well as its return value.
List of currently supported functions:
cFormatExpression | cArrayName - Depends on the value of the nFunctionType parameter
Return Value:
Depends on value of the nFunctionType parameter (see documentation for nFunctionType parameter above). RegExp() will return a logical value indicating whether a match was found if nFunctionType is 0. RegExp() will return a formatted character string if nFunctionType is 1. RegExp(), after succefully creating the array of splits will return the number of elements (number of splits) if nFunctionType is 2.
Example of use: (cut-n-paste the following code into a PRG and execute it from within Visual FoxPro)
*!* The following simple example shows how to use the RegExp()*!* function to validate, format, and split credit card numbersCLEAR
*!* Let Visual FoxPro know about the new function*!* by setting the library to the regexp.fllSET LIBRARY TO LOCFILE("regexp.fll","FLL","Locate regexp.fll")
LOCAL lcExpressionlcExpression = "\A(\d{3,4})[- ]?(\d{4})[- ]?(\d{4})[- ]?(\d{4})\z"
? "Pattern Matches:"*!* Validate credit card number using RegExp()?RegExp("1234-5678-9101-1121",lcExpression) && Match Found?RegExp("123-567-910-112", lcExpression) && No Match Found?
?"Formatting:"*!* Format credit card number using RegExp()?RegExp("1234567891011121",lcExpression, 1, "\1-\2-\3-\4") && Match Found?RegExp("12345678910111", lcExpression, 1, "\1-\2-\3-\4") && No Match Found?
*!* Split credit card number using RegExp()?"Splits: " + TRANSFORM(RegExp("1234-5678-9101-1121",lcExpression, 2, "arySplits")) && Matches FoundShowSplits()?"Splits: " + TRANSFORM(RegExp("1234-5678-9101-112", lcExpression, 2, "arySplits")) && No Matches FoundShowSplits()
*!* release the library referenceSET LIBRARY TO
***************************Procedure ShowSplits()*************************** LOCAL lnCounter FOR lnCounter = 1 TO ALEN(arySplits) ? CHR(9) + TRANSFORM(lnCounter) + ": " + arySplits(lnCounter) ENDFOR ?ENDPROC
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u