带有方括号的标记之间的PHP正则表达式内容

时间:2017-09-13 09:53:48

标签: regex

我正在尝试创建一个正则表达式,它会为我提供[start-flashcards][end-flashcards]之间出现的所有内容

我正在使用\[start-flashcards\](.*?)\[end-flashcards\],但这并不匹配。我肯定错过了什么?

<p>[start-flashcards]</p>
  <p>[London|This is the capital city of the United Kingdom]</p>
  <p>[Paris|This is the capital city of France]</p>
  <p>[Madrid|This is the capital city of Spain]</p>
  <p>[Tokyo|This is the capital city of Japan]</p>
  <p>[Moscow|This is the capital city of Russia]</p>
<p>[end-flashcards]</p>

1 个答案:

答案 0 :(得分:0)

你需要这个:

\[start-flashcards\]([\s\S]*?)\[end-flashcards\]

您使用了.,它与换行符不匹配。

编辑:

原来有一种实现相同目标的有效方法:

将正则表达式\[start-flashcards\](.*?)\[end-flashcards\]/s修饰符标记一起使用。此标志允许.匹配换行符。

相关问题