A
_ fixing issues listed in commentsI've come to your problem with REGEX:
^(?:[\w \/]*\:(?:(?!\n\n|\n[\w ]+\:).)*)|\* \* \* https://regex101.com/r/71p2QL/2 How does regex work?First house with a numerical alpha pattern followed by : (the key word);Then marry all characters after : what No contain two line breaks together \n\n (the content of the keyword) OR No contain a line break \n followed by a numerical alpha that precedes a two points [\w ]+\:orHouse with * * *gets a little tricky to understand here, but looking at the code I think it gets easierHow to use in the code?would like to put each of these blocks in the same line as your keywordWith this expression, we managed to separate all groups in memory and then it is only reassemble by applying the correctness it needs.In that case, you just need to make one .replace in all \n (or) \r\n) contained in each group.Code: (provided by regex101)import reregex = r"^(?:[\w \/]*\:(?:(?!\n\n).)*)|\* \* \*"
test_str = ("SAMPLE TYPE / MEDICAL SPECIALTY:Dermatology \nSAMPLE NAME: Epidermal Autograft \n\nDESCRIPTION:A 60% total body surface area flame burns, status post multiple prior excisions and staged graftings. Epidermal autograft on Integra to the back and application of allograft to areas of the lost Integra, not grafted on the back. \n(Medical Transcription Sample Report) \n\n* * *\n\nPREOPERATIVE DIAGNOSIS: A 60% total body surface area flame burns, status post multiple prior excisions and staged graftings. \nfim here\nPOSTOPERATIVE DIAGNOSIS: A 60% total body surface area flame burns, status post multiple prior excisions and staged graftings. \n\nPROCEDURES PERFORMED: \n1\. Epidermal autograft on Integra to the back (3520 cm2). \n2\. Application of allograft to areas of the lost Integra, not grafted on the\nback (970 cm2). \n\nANESTHESIA:General endotracheal. \n\nESTIMATED BLOOD LOSS: Approximately 50 cc. \n\nBLOOD PRODUCTS RECEIVED: One unit of packed red blood cells. \n\nCOMPLICATIONS:None. \n\nINDICATIONS:The patient is a 26-year-old male, who sustained a 60% total body surface area flame burn involving the head, face, neck, chest, abdomen, back, bilateral upper extremities, hands, and bilateral lower extremities. He has previously undergone total burn excision with placement of Integra and an initial round of epidermal autografting to the bilateral upper extremities and hands. His donor sites have healed particularly over his buttocks and he returns for a second round of epidermal autografting over the Integra on his back utilizing the buttock donor sites, the extent they will provide coverage. \n\nOPERATIVE FINDINGS: \n1\. Variable take of Integra, particularly centrally and inferiorly on the\nback. A fair amount of lost Integra over the upper back and shoulders. \n2\. No evidence of infection. \n3\. Healthy viable wound beds prior to grafting. \n\nPROCEDURE IN DETAIL: The patient was brought to the operating room and positioned supine. General endotracheal anesthesia was uneventfully induced and an appropriate time out was performed. He was then repositioned prone and perioperative IV antibiotics were administered. He was prepped and draped in the usual sterile manner. All staples were removed from the Integra and the adherent areas of Silastic were removed. The entire wound bed was further prepped with scrub brushes and more Betadine followed by a sulfamylon solution. Hemostasis of the wound bed was ensured using epinephrine-soaked Telfa pads. Following dermal tumescence of the buttocks, epidermal autografts were harvested 8 one-thousandths of an inch using the air Zimmer dermatome. These grafts were passed to the back table where they were meshed 3:1. The donor sites were hemostased using epinephrine-soaked Telfa and lap pads. Once all the grafts were meshed, we brought them back up onto the field, positioned them over the wounds beginning inferiorly and moving cephalad where we had best areas of Integra engraftment. We were happy with the lie of the grafts and they were stapled into place. The grafts were then overlaid with Conformant 2, which was also stapled into place. Utilizing all of his buttocks skin, we did not have enough to cover his entire back, so we elected to apply allograft to the cephalad and a few areas on his flanks where we had had poor Integra engraftment. Allograft was thawed and meshed 1:1. It was then brought up onto the field, trimmed to fit and stapled into place over the wound. Once the entirety of the posterior wounds on his back were covered out with epidermal autograft or allograft sulfamylon soaked dressings were applied. Donor sites on his buttocks were dressed in Acticoat and secured with staples. He was then repositioned supine and extubated in the operating room having tolerated the procedure without any apparent complications. He was transported to PACU in stable condition. \n\nKEYWORDS:dermatology, flame burns, body surface area, epidermal autograft, autograft, integra, integra engraftment, wound, grafts, epidermal, allograft\n")
matches = re.finditer(regex, test_str, re.MULTILINE | re.DOTALL)
for matchNum, match in enumerate(matches):
matchNum = matchNum + 1
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group().replace('\n', ' ')))
Result:Match 1 was found at 0-45: SAMPLE TYPE / MEDICAL SPECIALTY:Dermatology
Match 2 was found at 46-79: SAMPLE NAME: Epidermal Autograft
Match 3 was found at 81-363: DESCRIPTION:A 60% total body surface area flame burns, status post multiple prior excisions and staged graftings. Epidermal autograft on Integra to the back and application of allograft to areas of the lost Integra, not grafted on the back. (Medical Transcription Sample Report)
Match 4 was found at 365-370: * * *
Match 5 was found at 372-508: PREOPERATIVE DIAGNOSIS: A 60% total body surface area flame burns, status post multiple prior excisions and staged graftings. fim here
Match 6 was found at 509-637: POSTOPERATIVE DIAGNOSIS: A 60% total body surface area flame burns, status post multiple prior excisions and staged graftings.
Match 7 was found at 639-819: PROCEDURES PERFORMED: 1. Epidermal autograft on Integra to the back (3520 cm2). 2. Application of allograft to areas of the lost Integra, not grafted on the back (970 cm2).
Match 8 was found at 821-855: ANESTHESIA:General endotracheal.
Match 9 was found at 857-901: ESTIMATED BLOOD LOSS: Approximately 50 cc.
Match 10 was found at 903-965: BLOOD PRODUCTS RECEIVED: One unit of packed red blood cells.
Match 11 was found at 967-988: COMPLICATIONS:None.
Match 12 was found at 990-1605: INDICATIONS:The patient is a 26-year-old male, who sustained a 60% total body surface area flame burn involving the head, face, neck, chest, abdomen, back, bilateral upper extremities, hands, and bilateral lower extremities. He has previously undergone total burn excision with placement of Integra and an initial round of epidermal autografting to the bilateral upper extremities and hands. His donor sites have healed particularly over his buttocks and he returns for a second round of epidermal autografting over the Integra on his back utilizing the buttock donor sites, the extent they will provide coverage.
Match 13 was found at 1607-1859: OPERATIVE FINDINGS: 1. Variable take of Integra, particularly centrally and inferiorly on the back. A fair amount of lost Integra over the upper back and shoulders. 2. No evidence of infection. 3. Healthy viable wound beds prior to grafting.
Match 14 was found at 1861-3865: PROCEDURE IN DETAIL: The patient was brought to the operating room and positioned supine. General endotracheal anesthesia was uneventfully induced and an appropriate time out was performed. He was then repositioned prone and perioperative IV antibiotics were administered. He was prepped and draped in the usual sterile manner. All staples were removed from the Integra and the adherent areas of Silastic were removed. The entire wound bed was further prepped with scrub brushes and more Betadine followed by a sulfamylon solution. Hemostasis of the wound bed was ensured using epinephrine-soaked Telfa pads. Following dermal tumescence of the buttocks, epidermal autografts were harvested 8 one-thousandths of an inch using the air Zimmer dermatome. These grafts were passed to the back table where they were meshed 3:1. The donor sites were hemostased using epinephrine-soaked Telfa and lap pads. Once all the grafts were meshed, we brought them back up onto the field, positioned them over the wounds beginning inferiorly and moving cephalad where we had best areas of Integra engraftment. We were happy with the lie of the grafts and they were stapled into place. The grafts were then overlaid with Conformant 2, which was also stapled into place. Utilizing all of his buttocks skin, we did not have enough to cover his entire back, so we elected to apply allograft to the cephalad and a few areas on his flanks where we had had poor Integra engraftment. Allograft was thawed and meshed 1:1. It was then brought up onto the field, trimmed to fit and stapled into place over the wound. Once the entirety of the posterior wounds on his back were covered out with epidermal autograft or allograft sulfamylon soaked dressings were applied. Donor sites on his buttocks were dressed in Acticoat and secured with staples. He was then repositioned supine and extubated in the operating room having tolerated the procedure without any apparent complications. He was transported to PACU in stable condition.
Match 15 was found at 3867-4019: KEYWORDS:dermatology, flame burns, body surface area, epidermal autograft, autograft, integra, integra engraftment, wound, grafts, epidermal, allograft
https://repl.it/EYam/1