php - 如果冒号是第一个字符,则删除它

标签 php regex

仅当冒号是字符串的第一个字符时,我才想删除它。我已经尝试过以下方法,但它不起作用。任何帮助将不胜感激:

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

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

最佳答案

转义冒号:

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

关于php - 如果冒号是第一个字符,则删除它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10371175/

相关文章:

php - CodeIgniter + jQuery Ajax 运行错误但成功调用回调

PHP - 50% 的时间输出 2 个不同的链接

javascript - 用于传递空格和单引号的正则表达式

javascript - jquery:如何在html中查找单个字符

python - 已验证多行正则表达式在 notepad++ 中有效,但在 python 中没有结果

php - Symfony 渲染模板到字符串

javascript - opencart 联系页面验证码未出现

php - Xdebug 在 Ubuntu 中正确加载,但 var_dump/错误处理没有被覆盖

Python 正则表达式和版权符号

c# - 在 C# 中匹配换行符 (\n) 的正则表达式