findall and search text between 2 strings

PHOTO EMBED

Wed Jul 14 2021 15:08:10 GMT+0000 (Coordinated Universal Time)

Saved by @QuinnFox12 #python #textpreprocessing #nlp

import re

text = 'this is a text'

try:
    found = re.search('is(.+?)text', text).group(1)
except AttributeError:
    # AAA, ZZZ not found in the original string
    found = '0 wtitle' # apply your error handling
found

=> a

# To get more than 1 search
job_title = []
for i in range(0,9282):
    text = data.work_experiences.iloc[i]
    try:
        title = re.findall(r"wtitle (.*?) wcompany",text)
    except :
        title = 'onejob'
    job_title.append(title)
    
data['job_title'] = job_title
content_copyCOPY