I have the content of an English dictionary at hand and I want to find the definition for a specific example sentence.
For example, I want to find the definition for "example sentence 2b". In my opinion, the code may look lile this:
re.search(r'\d\. ([^\n]*?)\n(?!.*\d\. ).*?example sentence 2b', content, flags=re.DOTALL)
Here, the "content" is as follows:
1. definition1
example sentence 1a
example sentence 1b
2. definition2
example sentence 2a
example sentence 2b
3. definition3
example sentence 3a
example sentence 3b
Live test here - https://regex101.com/r/UOz6DA/1/
As you can see in the live test, I didn't get desired match - "definition2". I really don't know why.
PS: I used (?!.*\d\. ).*
based on this post - regex how to exclude specific characters or string anywhere