gpt4 book ai didi

PHP、正则表达式和 preg_replace,需要一些帮助

转载 作者:可可西里 更新时间:2023-10-31 22:58:27 25 4
gpt4 key购买 nike

我需要一些更换的帮助:

Some text [ id ]

为了...

Some text | id

我是正则表达式的新手,我只是不知道如何安全地将文本保存在 [ ] 中...而且我不想使用 str_replace 和 trim...我必须使用表达式(不要问为什么 :D )...有人可以帮助我吗?

最佳答案

这应该适用于非嵌套方括号:

preg_replace("/\[(.*?)\]/", "|$1", "Some text [ id ]")

输出

Some text | id

关于PHP、正则表达式和 preg_replace,需要一些帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7161553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com