Извлечение текста между двумя подстроками с использованием многострочного регулярного выражения в python - PullRequest
0 голосов
/ 22 марта 2020

Я хочу извлечь текст между двумя подстрокой или фразами, используя python, используя регулярное выражение.

Пример текста:

NAME – Testing set ADDRESS – 1470 ROAD CONTACT NUMBER - +91-44578558774 E-MAIL – test.side@gmail.com 


PROFESSIONAL PROFILE 

A petroleum graduate with professional experience in workover operation & Surface Well Testing operation and implementation of procedures and best practices following knowledge management processes. Seeking a role in oil and gas industry to develop engineering and management skills and apply new ideas to real life industry problem. 


PROFESSIONAL EXPERIENCE 

RIG (JUN 2014 – SEPT 2015)  

Performed various workover operations in SRP and ESP wells developed in Ahmedabad (ONGC Project) & Durgapur (ESSAR Project). My responsibilities as Roustabout on Rig was to perform:  Make pipe connection & Operate Tongs while running in and Pull out of Sucker rod & Tubings.

CORE COMPETENCIES: 

1. Well versed with varioussoftware for well testing (Wireless software). 2. Good Knowledge of MS-EXCEL, MS-Word.

Каким будет регулярное выражение для извлечения всего текста между ПРОФЕССИОНАЛЬНЫЙ ПРОФИЛЬ и ОСНОВНЫЕ КОМПЕТЕНЦИИ ? Я не могу понять правильное выражение.

1 Ответ

0 голосов
/ 22 марта 2020

Чтобы продолжить с комментариев ... Попробуйте это как демонстрацию ...

import re

pattern = re.compile(r'PROFESSIONAL PROFILE([\s\S]+)CORE COMPETENCIES:')

data = '''
NAME – Testing set ADDRESS – 1470 ROAD CONTACT NUMBER - +91-44578558774 E-MAIL – test.side@gmail.com 


PROFESSIONAL PROFILE 

A petroleum graduate with professional experience in workover operation & Surface Well Testing operation and implementation of procedures and best practices following knowledge management processes. Seeking a role in oil and gas industry to develop engineering and management skills and apply new ideas to real life industry problem. 


PROFESSIONAL EXPERIENCE 

RIG (JUN 2014 – SEPT 2015)  

Performed various workover operations in SRP and ESP wells developed in Ahmedabad (ONGC Project) & Durgapur (ESSAR Project). My responsibilities as Roustabout on Rig was to perform:  Make pipe connection & Operate Tongs while running in and Pull out of Sucker rod & Tubings.

CORE COMPETENCIES: 

1. Well versed with varioussoftware for well testing (Wireless software). 2. Good Knowledge of MS-EXCEL, MS-Word.

'''

#print(pattern.search(data)[1])
#I think the  is tripping the code up so consider...
print(pattern.search(data)[1].encode('utf8'))

Выходы:

A petroleum graduate with professional experience in workover operation & Surface Well Testing operation and implementation of procedures and best practices following knowledge management processes. Seeking a role in oil and gas industry to develop engineering and management skills and apply new ideas to real life industry problem. 


PROFESSIONAL EXPERIENCE 

RIG (JUN 2014 – SEPT 2015)  

Performed various workover operations in SRP and ESP wells developed in Ahmedabad (ONGC Project) & Durgapur (ESSAR Project). My responsibilities as Roustabout on Rig was to perform:  Make pipe connection & Operate Tongs while running in and Pull out of Sucker rod & Tubings.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...