

Using Masks to Specify Patterns in Strings › Sample Mask
Sample Mask
The following pattern allows precise filtering of the output of the DIR command in the Windows command shell:
([0-9]{2}/){2}[0-9]{2} *[0-9]{2}:[0-9]{2}(a|p) *[0-9,]+ [_~0-9a-zA-Z ]*(\.[_0-9a-zA-Z ]*)?
The following lines match this pattern:
10/26/05 07:03p 134,217,723 pagefile.sys
10/26/05 07:03p 1,024 testfile
The preceding lines are made up of the following elements:
- ([0-9]{2}/) represents character strings composed of two digits and a slash mark (/), as in “10/”.
- ([0-9]{2}/){2}[0-9]{2} builds on the previous element and specifies that the two-digit sequence can be repeated 3 times, each sequence being separated from the next by a slash mark, as in “10/26/05”.
- *[0-9]{2}:[0-9]{2}(a|p) matches any number of spaces followed by the time in the format hh:mm followed by “a” for AM or “p” for PM.
- *[0-9,]+ matches any number of spaces followed by any number of digits and commas for the file size.
- [_~0-9a-zA-Z]*(\.[_~0-9a-zA-Z]*)? represents a sequence of alphanumerical characters, underscores (_) and tildes (~), optionally followed by a period and another sequence. Because the period (.) is the dot operator, it is necessary to escape it using the escape character (\) when we intend to match it as a character.
The pattern in a mask may differ depending on the exact characters to be matched. For example, [\._~0-9a-zA-Z ]* instead of [_~0-9a-zA-Z]*(\.[_~0-9a-zA-Z]*)? could also match the file names in our example outputs, but without imposing any restraints on the number of periods (.) in the file name.
Copyright © 2013 CA.
All rights reserved.
 
|
|