"graph" Character Class.

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

Explanation

The [[:graph:]] is same as [[:print:]], but matches non-blank characters like alphabets, special characters, numbers but excludes spaces, control characters etc.

PHP Example:


<?php
$str = "LIIÏÏ ïï";
$pat = ereg_replace("[[:graph:]]","G",$str);
echo $pat;
echo "n<br>n";
?>
Result :

GGGÏÏ ïï

In the above example the character class "[[:graph:]]", is used in the "ereg_replace", and all non-blank character ie., "L","I" are replaced with the string "G". The control characters and spaces alone are left without replacing it with "G".

Perl Example:


#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$str = "344adsds.";
if ( $str =~ '[[:graph:]]$')
{print "Matches!";}
else
{print "Unmatch!";}
Result :

Matches!

In the above example, using the [[:graph:]] character class the end of the string is checked using "$", to check for any non-blank characters, so it matches.


Ask Questions

Ask Question