. (Wildcard character)
|Top Previous Next|
Matches any single character. It is used to specify an unknown portion in the string. Because the period is used in almost all Windows file names it is very common to forget that it has a very special meaning in regular expressions. If the user wishes to use the period literally in a search it must be preceded by the '\' escape character. For example:
If you entered the filename as the expression 'mydoc.doc' it would find any file that had 'mydoc' followed by any character followed by 'doc'. Therefore although it would find 'mydoc.doc' it would also find 'mydoc1doc' and 'mydocXdoc'. If you wanted to just search for 'mydoc.doc' the expression would be 'mydoc\.doc'.
If you entered the filename as the expression '^mydocument..\.txt$' it would find any file that began with 'mydocument' followed by exactly any two characters and ended with '.txt' (note the use of the '^' beginning of the string character, and the '\' escape character to treat the '.' in '.txt' literally, and the '$' end of the string character). Therefore it would find files such as 'mydocument_1.txt' and 'mydocument1a.txt' but would not find files such as 'mydocument.txt' and 'mydocument_1a.txt'.
The expression 'my.*\.txt' would find any file that includes 'my' followed by any number of characters followed by '.txt' (note the use of '*' to specify zero or more occurrences). Therefore it would find files such as 'my_examples.txt' and 'this is my file.txt.doc' but would not find files such as 'myfile.doc' and 'm_y_file.txt'.