preg_replace 特定模式
我想使用 preg_replace 将“* @license until */
”替换为“testing
”。
我该怎么做呢?
我的文字如下:
/*
* @copyright
* @license
*
*/
我希望大家能够正确理解我的问题。
I would like to use preg_replace to replace "* @license until */
" with "testing
".
How can I do it?
My text is the one below:
/*
* @copyright
* @license
*
*/
I hope everyone have understand my question correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个可以执行您想要的操作的正则表达式(以多行模式运行)
它与被删除的部分匹配:
说明:
请注意,正则表达式仍然必须根据 PHP 字符串规则和进行转义到
preg_replace()
规则。编辑:如果您愿意 - 要绝对确定在匹配的文本后面确实有一个注释结束标记,正则表达式可以像这样扩展:
Here is one regex that does what you want (run it in multi-line mode)
It matches the part that is striked:
Explanation:
Note that the regex must still be escaped according to PHP string rules and according to
preg_replace()
rules.EDIT: If you feel like it - to make absolutely sure that there really is an end-of-comment marker following the matched text, the regex can be expanded like this:
嗯,这并不太难。您需要做的就是使用
s
修饰符(PCRE_DOT_ALL,它使正则表达式中的.
匹配新行):这应该适合您(注意,未经测试)。 ..
Well, it's not too hard. All you need to do is use the
s
modifier (PCRE_DOT_ALL, which makes a.
in the regex match new lines):That should work for you (note, untested)...