I've already posted a similar question regarding the text extraction in Python with regular expressions, but I have another issue with non-greedy quantifiers, so I am asking a question with a little bit different example. The issue is I need to extract all the relevant portions of the string text by using regular expressions in Python with two specific matches. To be specific, here is an example text:
example = """
The Bank does offer a hybrid loan. Hybrid loans are loans that start as a
fixed rate mortgage but after a set number of years automatically adjust
to an adjustable rate mortgage. The Bank offers a three year fixed rate mortgage
after which the interest rate will adjust annually. Item 1. Business 3-13 Item 1a.
Risk Factors 13-15 Item 1b. Unresolved Staff Comments 15 Item 2. Properties 15-16
The forward-looking statements are made as of the date of this report,
and the Company assumes no obligation to update the forward-looking statements
or to update the reasons why actual results could differ from those projected
in the forward-looking statements. PART 1. ITEM 1. BUSINESS
General Farmers & Merchants Bancorp, Inc. (Company) is a bank holding company
incorporated under the laws of Ohio in 1985 and elected to become a financial
holding company under the Federal Reserve in 2014. Our primary subsidiary,
The Farmers & Merchants State Bank (Bank) is a\n community bank operating
in Northwest Ohio since 1897.ITEM 2. PROPERTIES Our principal office is located in Archbold, Ohio.
The Bank operates from the facilities at 307 North Defiance Street.
In addition, the Bank owns the property from 200 to 208 Ditto Street,
Archbold, Ohio, which it uses for Bank parking and a community mini-park area.
"""
, and and I would like to extract the 'between' portions of the text starting from a start match 'ITEM 1.' and an end match 'ITEM 2.', so the final results should look like this:
final_result_1 = """
ITEM 1. BUSINESS
General Farmers & Merchants Bancorp, Inc. (Company) is a bank holding company
incorporated under the laws of Ohio in 1985 and elected to become a financial
holding company under the Federal Reserve in 2014. Our primary subsidiary,
The Farmers & Merchants State Bank (Bank) is a\n community bank operating
in Northwest Ohio since 1897.
"""
final_result_2 = """
Item 1. Business 3-13 Item 1a.
Risk Factors 13-15 Item 1b. Unresolved Staff Comments 15
"""
The order of the final results should be in terms of the length of final result text, so the 'final_result_1' is the longest text portion out of two, and the 'final_result_2' is the shortest one. You could refer to the answers to the previous question here. Thank you in advance!