Regular Expressions

The dot special character

A dot . in a regular expression matches any single character except \n.

Example 1

You want to search for the date 21-12-1997, but you do not know whether it is written as 21-12-1997, 21/12/1997 or 21.12.1997. Write:
if ($date =~ /21.12.1997/) {...}

# the dot in the regular expression means "any character",
# not a literal dot.

# To match a literal dot precede it by a backslash: \.

Example 2

You want to search for the TABLE tag in an HTML document, which may or may not contain attributes.

e.g. all of the following are valid:



if ($doc =~ /<TABLE.*>/) { ... }

Table of Contents.