[Previous] [Contents] [Next]


Characters and wildcards

To represent any character in a pattern, a period is used as a wildcard. The pattern "c.." matches any three-letter string that begins with a lowercase "c"; for example, "cat", "cow", "cop", etc. To express a pattern that actually matches a period, use the backslash character \-for example, "\.com" matches ".com" but not "xcom".

The use of the backslash in a regular expression can cause confusion. To include a backslash in a double-quoted string, you need to escape the meaning of the backslash with a backslash. The following example shows how the regular expression pattern "\.com" is represented:

// Sets $found to true
$found = ereg("\\.com", "www.ora.com");

It's better to avoid the confusion and use single quotes when passing a string as a regular expression:

$found = ereg('\.com', "www.ora.com");


[Previous] [Contents] [Next]