Regular Expression Meta-character Wild "."

What is regular expression Wild character "."?

Explanation

In regular expression, the meta-character Wild "." or a wild character that can represent a single character.

In the pattern {o.*l} specifies a string with "o" followed by "l" with zero or more characters in between. The possible matches can be like "ol", "oshdfghdl", "odsdfl" etc.

PHP Example:


<?php
$string = 'caaa';
if (preg_match('/^(c.*t)/', $string))
echo "Regex Pattern match";
else
echo "Regex Pattern unmatch";
?>
Result :

Pattern unmatch

In the above example the pattern "^(c.*t)" specifies that the string should start with "c" with any character following and at the end with a "t".

Perl Example:


#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$name= "first name";
if ($name =~ m/fi(.*)me/)
{print "The name format matched!";}
else
{print "The name format not matched!";}
Result :

The name format matched!

In the above example's pattern ".*" represents the characters "rst na" and the rest of the characters are specified in the pattern.

Ask Questions

Ask Question