0
import re
a = """COMPUTATION OF DAMAGES Plaintiff Maurice’s computation of damages to date includes all the above related medical specials, totaling $98,429.00. The Minimally Invasive Hand Institute $49,949.00 Interventional Pain & Spine Institute $1,190.00 Premier Physical Therapy $8,600.00 Clinical Neurology Specialist $3,090.00 Red Rock Surgery Center $34,510.00 DIMOPOULOS INJURY This is the bill of 1 2 3 4 5 6 7  8 DIMOPOULOS INJURY """
word1 = "COMPUTATION OF DAMAGES"
word2 = "DIMOPOULOS INJURY"
result = re.search(word1 + '(.*)' + word2, a)
print(result.group(1))

Required op:  Plaintiff Maurice’s computation of damages to date includes all the above related medical specials, totaling $98,429.00. The Minimally Invasive Hand Institute $49,949.00 Interventional Pain & Spine Institute $1,190.00 Premier Physical Therapy $8,600.00 Clinical Neurology Specialist $3,090.00 Red Rock Surgery Center $34,510.00

How to extract text upto the first "DIMOPOULOS INJURY" keyword. Is there any solution

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Manu Raj
  • 19
  • 5

1 Answers1

1

You are very close, just add ?:

result = re.search(word1+'(.*?)'+word2, a)

The output will be: "Plaintiff Maurice’s computation of damages to date includes all the above related medical specials, totaling $98,429.00. The Minimally Invasive Hand Institute $49,949.00 Interventional Pain & Spine Institute $1,190.00 Premier Physical Therapy $8,600.00 Clinical Neurology Specialist $3,090.00 Red Rock Surgery Center $34,510.00"

Prashant Maurya
  • 639
  • 4
  • 13