I have the following text:
[FONT=arial, helvetica]this
is a multiline text
[/FONT]
[FONT=arial, helvetica] this is a single line comment[/FONT]
I'm trying to match the text inside the bbcode tags with this pattern:
\[FONT=(.*?)\](.*?)\[\/FONT\]\im
But it only matches the single line text, why? I've even added the multi-line flag.
答案 0 :(得分:3)
Instead of multiline flag you need single-line here.
/\[FONT=(.*?)\](.*?)\[\/FONT\]/isg
Single-line modifier makes dot symbol match newline characters as well - it is exactly your issue.
Multiline modifier only makes beginning/end characters (^
and $
) match start/end of line.
答案 1 :(得分:2)
\[FONT=([\s\S]*?)\]([\s\S]*?)\[\/FONT\]
You can also use this without any flags
.See demo.