space Character Class

What is [[:space:]]?


This character class identifies all space characters like "f" -form feed, "n"- newline, "r"- carriage return, "t" - tab, "v" -vertical tab.

PHP Example:

$chr = '23asd fgshgf';
$det = ereg_replace("[[:space:]]","X", $chr);
echo $det;
Result :


In the above example this regular expression is used with [[:alnum:]], along with "|" or operator to identify the presence of any space or alpha numeric character in the given string, and the string has all these characters, so its matched.

Perl Example:

#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$str = "sfg jh s@";
if ( $str =~ /[[:space:]]{2,4}/)
{print "Matches!";}
{print "Unmatch!";}
Result :


In the above example the pattern "[[:space:]]{2,4}" identifies consecutive spaces that should be above "2" and with a minimun of "4", so its unmatched as the string has single space.

Ask Questions

Ask Question