-2

I am trying to create a regex that will give me everything that appears between [start-flashcards] and [end-flashcards]

I am using \[start-flashcards\](.*?)\[end-flashcards\] but this doesn't match. I must be missing something?

<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>
Chris
  • 4,186
  • 11
  • 44
  • 79

1 Answers1

0

You need this:

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

You've used ., which doesn't match line-breaks.

EDIT:

Turns out there is an efficient way of achieving the same:

Use your regex \[start-flashcards\](.*?)\[end-flashcards\] with the /s modifier flag. This flag allows . to match newline characters.

CinCout
  • 8,291
  • 9
  • 47
  • 55