如果制表符位于字符串末尾,则为preg_match

时间:2016-01-22 15:06:39

标签: php preg-match

如何检查字符串末尾是否有标签?哪种模式有效?我试过了/\+t$/但我得到了#34;字符串末尾没有标签"即使最后有一个制表机构。

<?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";
}
?>

1 个答案:

答案 0 :(得分:2)

您的正则表达式/\+t$/匹配字符串末尾的+符号后跟字符t

我想你想要:

  • /\t$/:字符串末尾的制表
  • /\t+$/:最后一个或多个表格
相关问题