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

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


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

PHP Example:

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


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!";}
{print "Unmatch!";}
Result :


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