"cntrl" Character Class.

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

Explanation

The [[:cntrl:]] character class matches characters that dont give an output as such but still controls system. Some of the control characters are form feed, backspace, tabspace character etc. All these characters have ASCII value less than 31.

PHP Example:


<?php
$org = "IIÏÏïï";
$det = ereg_replace("[[:cntrl:]]","V",$org);
echo $det;
?>
Result :

IIVII

In the above example the character class "[[:cntrl:]]" is used to replace the tab space which is also a control character with "V".

Perl Example:


#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$str = "01";
if ($str =~ m/[[:cntrl:]]/)
{print "Matches!";}
else
{print "Unmatch!";}
Result :

Matches!

In the above example the control character ascii value "01" is matched using the character class "[[:cntrl:]]", since it displays matched.

Ask Questions

Ask Question