Regular expressions are a powerful pattern-matching tool. They allow patterns to be specified concisely and flexibly.

For example, a regular expression to match a Zip code might look like


-- 5 digits, optionally followed by a dash and 4 more digits.

Craig Boyd has written an FLL called RegExp that allows VFP to use regexps without calling out to a COM library, as the FFC class does. Using it, we see that:

lcZipRegex = "\d{5}(\-\d{4})?"

?regexp("02908", lcZipRegex)       && .T.
?regexp("02908-2148", lcZipRegex)  && .T.
?regexp("029082175", lcZipRegex)   && .F.

An equivalent comparison in Xbase code would be quite a bit wordier.

External linksEdit