"print" Character Class.

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

Explanation

The [[:print:]] character class matches all printable characters like alphabhets, numbers etc and it also
matches blank spaces too but the [[:graph:]] character class excludes spaces, otherwise it is same as [[:print:]]. But "control
characters" are unmatched by both of these character classes.

PHP Example:





<?php
$str = "LII ";
$pat = ereg_replace("[[:print:]]","G",$str);
echo $pat;
echo "<br>";
?>


Result :



GGGG




In the above example the character class "[[:print:]]" is used to match the printable characters which are alphabhets
"L", "I" and also blank spaces. The matched characters are replaced with "G". The string also has some control character
that are not matched by either [[:print:]] or [[:graph:]] character classes.

Perl Example1:




#! C:\programfiles\perl\bin\perl
print "content-type: text/html\n\n";
$str = "";
if ( $str =~ /[[:print:]]/)
{print "Matches!";}
else
{print "Unmatch!";}


Result :



Unmatch!




In the above example the string contains only non-printable characters that is "control charscters", so it's unmatched.

Perl Example 2:





#! C:\programfiles\perl\bin\perl
print "content-type: text/html\n\n";
$str = "FF09&@";
if ( $str =~ /[[:print:]]/)
{print "Matches!";}
else
{print "Unmatch!";}


Result :



Matches




In the above example the string has alphabhets, numbers, special characters all these are printable
characters so its matched.


Ask Questions

Ask Question