Regular Expressions

The dot character

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

Example 1

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

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

# To match a literal dot only, then 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.

i.e. all of the following are valid:

<TABLE>
<TABLE BORDER>
<TABLE CELLPADDING=3 ALIGN="center">

Write:

if ($html =~ /<TABLE.*>/) {
  ____;
  ____;
  ____;  
}


Table of Contents.
Previous | Next.