OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

The Any Character

The first metacharacter we will look at is the dot or period character, which is used to match any character. If we include it in a regular expression, it will match any character in that character position. Here’s an example:



[me@linuxbox ~]$ grep -h '.zip' dirlist*.txt

bunzip2 bzip2 bzip2recover gunzip

gzip funzip gpg-zip preunzip prezip

prezip-bin unzip unzipsfx

[me@linuxbox ~]$ grep -h '.zip' dirlist*.txt

bunzip2 bzip2 bzip2recover gunzip

gzip funzip gpg-zip preunzip prezip

prezip-bin unzip unzipsfx


We searched for any line in our files that matches the regular expression “.zip”. There are a couple of interesting things to note about the results. Notice that the zip program was not found. This is because the inclusion of the dot metacharacter in our regular expression increased the length of the required match to four characters, and because the name “zip” only contains three, it does not match. Also, if any files in our lists had contained the file extension .zip, they would have been matched as well, because the period character in the file extension would be matched by the “any character,” too.

Anchors


Top OS Cloud Computing at OnWorks: