How to check if there is a tab at the end of a string? Which pattern works? I tried /\+t$/
but i get "There is NO tab at the end of the string" even though there is a tabulator at the end.
<?php
$text = "Come to the dark side. We have cookies ";
$pattern = "/\+t$/";
if(preg_match($pattern , $text))
{
echo "There is a tab at the end of the string";
}
else
{
echo "There is NO tab at the end of the string";
}
?>
Your regex /\+t$/
matches a +
sign followed by character t
at the end of a string.
I guess you want :
/\t$/
: a tabulation at the end of the string/\t+$/
: one or more tabulations at the end