blank Character Class in Regular expression

What is [[:blank:]] Character Class in regex?


The [[:blank:]] represents horizontal space, tab-space characters in regular expression.

PHP Example:

$str = 'A12 34ax$ xxxx';
$ret = ereg_replace("[[:upper:]]|[[:blank:]]","B",$str);
echo $ret;
Result :


In the above example for regex the character class "[[:blank:]]" is used along with "[[:upper:]]" to match a string that is in uppercase and having one or more tab or blank-space.

Perl Example:

#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$str = "A A AA";
if ( $str =~ /[[:blank:]]{1,2}/ )
{print "Matches!";}
{print "Unmatch!";}
Result :


In the above example for regex the string "A A AA" has a two blank-spaces, so does tha pattern "[[:blank:]] {1,2}" which specifies number of blank-spaces minimum "1" space and utmost "2" blank-spaces.

Ask Questions

Ask Question