Inexact Matches in Regular Expressions

Domain Hosting image
Web Hosting
Dedicated server
ssl certificate
Web Design image
Email

The previous examples use exact for the regular expressions. You give the exact characters you want to match. However, you often don't know the exact characters for which you are looking. For example, you may be searching for "the letter x or the letter X,"or"one or more hash characters," or even "a hash character followed by any other character followed by a hash character. Regular expressions make these kind of inexact matches fairly easy.

To indicate that you want to match either one character or another, you use the variable bar (1) between each character you may want to match. This is called alternating because you give Perl a list of alternates to look for. For example, to search for either "x* or X, you may use

if($Test =~/(xiX)/) . .

This code will match exactly one *x" or "V.

Like in numeric equations, you can use parentheses around a group of related items in your regular expression. You can have more than one kind of thing in a regular expression, such as a fixed expression and alternating list. For example, to search for "candle,* 'candy, and "cancer", you coule use

if($Test =~ /can(dleldylcer)/). . .

If you don't know which character you want to match, you use a period as a wildcard character. For example, if you want to match "the letter N followed by any character followed by the letter T," you would use

if($Test = /N T/) ...



Domain Name Search

www.


Copyright (C) 2007. Web Domain design hosting. All rights reserved.