gpt4 book ai didi

php - 匹配多行文本

转载 作者:行者123 更新时间:2023-12-02 07:57:42 24 4
gpt4 key购买 nike

我有以下文字:

[FONT=arial, helvetica]this

is a multiline text

[/FONT]

[FONT=arial, helvetica] this is a single line comment[/FONT]

我正在尝试将 bbcode 标签内的文本与此模式匹配:

\[FONT=(.*?)\](.*?)\[\/FONT\]\im

但是它只匹配单行文本,为什么?我什至添加了多行标志。

http://www.regexr.com/3b72f

最佳答案

这里需要单行,而不是多行标志。

/\[FONT=(.*?)\](.*?)\[\/FONT\]/isg

单行修饰符使点符号也匹配换行符 - 这正是您的问题。

多行修饰符仅使开始/结束字符(^$)匹配行的开始/结束。

关于php - 匹配多行文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30847906/

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