upper Character Class

Whats the use [[:upper:]]?


This identifies uppercase alphabets that is from [A-Z].

PHP Example:

$str = "AAAAbbbbcccc";
$pat = ereg_replace("[[:upper:]]","a",$str);
echo $pat;
echo "n<br>n";
Result :


In the above example, the character class is used with ereg_replace. ereg_replace, replaces with string "a" as mentioned. Now,the regular expression identifies 'A' in the given string and ereg_replace replaces it with string "a" that is, in the string given "AAAAbbbbCCCC" having uppercase "A" with an lowercase "a".

Perl Example:

#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$str = "AAsfasaAA";
$str =~ s|[[:upper:]]|X|g;
print"Replaced String is $str";
Result :

Replaced String is XXsfasaXX

In the above example the same pattern is used to search and replace operator in perl "s///" with a global scope "g" to replace every occurence of a string, so using the pattern "s|[[:upper:]]|X|g" every occurence of an uppercase alphabets is replaced by "X".

Ask Questions

Ask Question