Regular Expressions

Flashcard 3 of 10

The following sample text contains keywords wrapped in a pair of % characters. Our goal is to slice out each of these keywords, collected in an array.

string = "The %start% and %end% of the content..."

string.scan(/%.*%/)
#=> ["%start% and %end%"]

Unfortunately, it looks like our pattern is grabbing one long string rather than the two distinct matches we were hoping to get.

How can we alter our pattern to fix this issue?

Answer:

Reveal Answer