只保留连续重复的指定字符的一个实例
我有一个字符串 !!test
或 !!!!!测试。
我想要做的是使用 preg_replace()
并仅保留第一个 !
但保留第一个 !
之后的其余文本> 这不是 !
!!test
-> !测试
I have a string !!test
or !!!!! testing
.
What I want to be able to do is use preg_replace()
and only keep the first !
but keep the rest of the text after that first !
that is not a !
!!test
-> !test
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将多个
!
替换为单个!
。http://www.regular-expressions.info/ 有一些很棒的教程和参考资料用于学习正则表达式。
Replace multiple
!
s with a single!
.http://www.regular-expressions.info/ has some great tutorials and references for learning regular expressions.
适用于两个示例。
Works for both examples.