简体   繁体   English

在python中使用正则表达式多行提取两个子字符串之间的文本

[英]Extract text between two substrings using regular expression multiline in python

I want to extract text between two substring or phrases using python using regular expression.我想使用正则表达式使用 python 提取两个子字符串或短语之间的文本。

Sample text:示例文本:

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.

What will the regex be for extracting all the text between PROFESSIONAL PROFILE and CORE COMPETENCIES ?用于提取PROFESSIONAL PROFILECORE COMPETENCIES之间的所有文本的正则表达式是什么? I am not able to get the regex right.我无法正确使用正则表达式。

To continue from the comments...Try this as a demo...从评论继续......试试这个作为演示......

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'))

Outputs:输出:

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 正则表达式:多行模式匹配两个以上的子字符串 - Python Regular Expression: Multiline pattern match with more than two substrings 如何在python中的多行字符串中提取两个子字符串之间的字符串部分 - how to extract portion of a string between two substrings in a multiline string in python Python正则表达式提取两个值之间的文本 - Python regular expression extract the text between two values Python:正则表达式以提取html中任意两个标签之间的文本 - Python: Regular expression to extract text between any two tags in a html 使用 python 在两个字符串之间提取多行文本 - Extract multiline text between two strings using python 如何在Python中使用正则表达式提取某些字符之间的所有子字符串? - How to extract all substrings between certain characters by using regular expression in Python? 使用正则表达式在python中提取两个字符串之间的字符串 - extract strings between two strings in python using regular expression 使用正则表达式提取子字符串 - Extract substrings with regular expression 使用 Python 中的 re.search(pattern, text) 在两个指定子字符串之间提取 substring - Extract substring between two specified substrings using re.search(pattern, text) in Python python正则表达式。在模式之间提取文本 - python regular expression. Extract text between patterns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM