[Up] Reference for unit 'Masks' (#lazutils)

Masks Overview.

What is a Mask

A mask is an expression composed of literal characters, character sets, and wildcards. A mask is used in TMask and related routines to determine if a string containing a specific value matches the mask expression.

Literal Characters

Each literal character corresponds to a single character in a compared value.

Character Sets

A character set begins with an opening Square Bracket character ([) and ends with a closing Square Bracket character (]). Values between the brackets represent literal characters or a range of characters which are included in (or excluded from) the character set.

A range is defined using a starting character, a dash (-), and an ending character. The character set matches a single character in a compared value. When an Exclamation Point character (!) is found after the first bracket, the values in the character set are excluded from matches using the mask.

For example, an alpha-numeric character set could be represented using the following:

[a-zA-Z0-9]

And, a character set which excludes numeric values could be represented using the following:

[!0-9]

Wildcard Characters

Wildcard characters allow one or more literal characters to be considered as a match in the mask value, and includes the ? and * characters. ? matches a single character (regardless of its value). * matches any number of characters (regrardless of their values).

Mask Examples

abc.ext
Matches a single file named "abc.ext".
a[blt]c.ext
Matches "abc.ext", "alc.ext", or "atc.ext".
a[b-d]c.ext
Matches "abc.ext", "acc.ext", or "adc.ext".
foo*
Matches any file that starts with "foo", including those with a file extension.
*
Matches any file, including those with a file extension.
*.
Matches any file that does not have an extension.
ab??ef.txt
Matches abcdef.txt and abrtef.txt.

Using Masks

Mask values are normally passed as an argument to new instances of TMask, or passed as an argument to routines like MatchesMask, MatchesMaskList, et. al. In general, the mask is used to find file names that match the mask expression. But they are not limited that single use case. They can be used to determine if any string value matches a valid mask expression. They are like regular expressions without all of the complexity (and most of the functionality).

Remark: Mask values as used in TMask are not related to the mask values used in the TMaskEdit control. Although both compare string values to determine if they match a particular pattern, they use different symbols and syntax.