I have data in a text file "file.txt"
Recipes & Menus
Expert Advice
Ingredients
Holidays & Events
Community
Video
SUMMER COOKING
Lentil and Brown Rice Soup
Gourmet January 1991
3.5/4
reviews (83)
90%
make it again
Some soups genuinely do inspire a devotion akin to love, and this is one of
them. In the cold of winter, when Gourmet editors ponder the matter of what soup
Cook
Reviews (83)
YIELD: Makes about 14 cups, serving 6 to 8
Ingredients
5 cups chicken broth
1 1/2 cups lentils, picked over and rinsed
1 cup brown rice
a 32- to 35-ounce can tomatoes, drained, reserving the juice, and chopped
3 carrots, halved lengthwise and cut crosswise into 1/4-inch pieces
1 onion, chopped
1 stalk of celery, chopped
3 garlic cloves, minced
1/2 teaspoon crumbled dried basil
1/2 teaspoon crumbled dried orégano
1/4 teaspoon crumbled dried thyme
1 bay leaf
1/2 cup minced fresh parsley leaves
2 tablespoons cider vinegar, or to taste
Preparation
In a heavy kettle combine the broth, 3 cups water, the lentils, the rice, the tomatoes with the reserved juice,
I want to extract the data between Ingredients and Preparation.
I had written the following regex for it :-
(?s).*?Ingredients(.*?)Preparation.*
But it's extracting the data between the Ingredients in italics on 3rd line of
file.txt and Preparation but not between the data between Ingredients and Preparation
What changes in my regex code should I do to resolve this problem?
Thanks in advance!
Try making your first
.*
greedy. It will eat allIngredients
up until the last one beforePreparation
:Demo: https://regex101.com/r/mQ5eK5/1