Regular Expression Meta-character Dollar "$"

What is Regular Expression meta-character Dollar "$"?

Explanation

In Regular Expression, the dollar symbol "$" meta-character is used to find the matching character's from the end of a string.

PHP Example:


<?php
$string = "This is a *";
if (preg_match("/*$/", $string))
{
echo "Pattern found at the end!";
}
else
{
echo "Pattern not found!";
}
?>
Result :

Pattern found at the end!

In the above regex example the end of the string is matched for the character "*", and its matched.

Perl Example:


#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
if ("This is a vessle" =~ m/el$/)
{
print "The regex pattern found at the end.!n";
}
else
{
print "The regex pattern not found!n";
}
Result :

The pattern not found!

In the above Regular Expression's example, the string is checked for the pattern "el" at the end of the string "vessel", but its unmatched as the last two characters are "el".


Ask Questions

Ask Question