How to use [[:lower:]] Character Class.

What is [[:lower:]] Character Class?

Explanation

The "[[:lower:]]" represent's lower case alphabets that is from [a-z].

PHP Example:


<?php
$str = "AAAAbbbbCCCC";
$pat = ereg_replace("[[:lower:]]","B",$str);
echo $pat;
echo "n<br>n";
?>
Result :

AAAABBBBCCCC

In the above example the character class "[[:lower:]]", is used in the "ereg_replace" command to replace the string "AAAAbbbbCCCC" having lower case "b's" with an upper case "B".

Perl Example:


#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$str = "dsADSDSDs";
if ( $str =~ /[[:lower:]]{2,3}/)
{print "Matches!";}
else
{print "Unmatch!";}
Result :

Matches!

In the above example the string is checked using the pattern [[:lower:]] to have 2 to 3 given in braces "{2,3}" lowercase characters, so its matched as the string has 3 lowercase letters.

Ask Questions

Ask Question