0

I have a text file that contains data in the form :

This recipe can be made either with a stand mixer, or by hand with a bowl, a wooden spoon, and strong arms. If you use salted butter, please omit the added salt in this recipe.
Yum
Ingredients
1 1/4 cups all-purpose flour (160 g)
1/4 teaspoon salt
1/2 teaspoon baking powder
1/2 cup unsalted butter (1 stick, or 8 Tbsp, or 112g) at room temperature
1/2 cup white sugar (90 g)
1/2 cup dark brown sugar, packed (85 g)
1 large egg
1 teaspoon vanilla extract
1/2 teaspoon instant coffee granules or instant espresso powder
1/2 cup chopped macadamia nuts (3 1/2 ounces, or 100 g)
1/2 cup white chocolate chips
Method
Preheat the oven to 350°F (175°C). Vigorously whisk together the flour, salt and baking powder in a bowl and set aside.

I need to extract the data between words Ingredients and Method.
How can I do that using regex in scala?

  • Doesn't [this answer](http://stackoverflow.com/questions/7360686/regex-how-to-find-text-between-two-strings) your question? Or maybe [Extract string between two strings in Scala](http://stackoverflow.com/questions/25501456/extract-string-between-two-strings-in-scala) is even better? – Wiktor Stribiżew May 27 '15 at 11:39
  • Have you considered that a solution without regexp might be simpler? – reto May 27 '15 at 11:43
  • Have you tried parser combinators? – Daenyth May 27 '15 at 22:01

1 Answers1

0

Use (?s) DOTALL modifier to make dot in your regex to match line breaks also.

(?s)(?<=\bIngredients\b).*?(?=\bMethod\b)
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
  • Thanks for the regex. As I am new to Scala, can you please tell me the scala code that I should write after defining the regex to extract the data. – user3663737 May 27 '15 at 21:21