如果它是第一个字符,请删除冒号

时间:2012-04-29 09:43:14

标签: php regex colon

我想仅在字符串的第一个字符时删除冒号。我尝试了以下但它不起作用。任何帮助将不胜感激:

//remove the colon if its the first character..

$pattern = '/^:/';
$replace = '';
$tweet = preg_replace($pattern, $replace, $tweet);

2 个答案:

答案 0 :(得分:3)

逃离冒号:

$pattern = '/^\\:/';

答案 1 :(得分:2)

您也可以将冒号放在一个集合中,这可能更容易阅读:

$pattern = '/^[:]/';
相关问题