xdigit Character Class

What is the use of [[:xdigit:]]?

Explanation

This character class helps in finding hexadecimal digit character.

PHP Example:


<?php
$chr = 'WAB10BC99GZ';
$dgt = ereg_replace("[[:xdigit:]]","#", $chr);
echo $dgt;
?>
Result :

W########GZ

In the above example, the regular expression matches given with hexadecimal digit character. Since the string is matched, it displays "all are hex chars".

Perl Example:


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

UnMatch!

In the above example we matched a string given as "GG", using the same pattern.

Ask Questions

Ask Question