Tabspace "t" metacharacter in Regular Expression.

How is "t" metacharacter is used in regular expression?


The "t" metacharacter is used to match any tabspace in regex.

PHP Example:

$str = "hiox india";
if (preg_match("/t/", $str, $matches))
echo "Pattern matches!";
echo "Pattern not matched!";
Result :

Pattern matches!

In the above example for regex the string "$str" has a tab space, so it matches.

Perl Example:

#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$str = "hi how are you";
if ($str =~ m/t/)
{print "It's matched!";}
{print "It's not matched!";}
Result :

It's not matched!

In the above tabspace metacharacter example for regex the pattern "/t/" is unmatched as the string does not have any tab spaces.

Ask Questions

Ask Question