SATYAMEDHAS PANDE
SATYAMEDHAS PANDE

Reputation: 11

How do I extract the entire sentence from a job description which consists the number of years of experience in it?

I've been working on a job description parser and I have been trying to extract the entire sentence which consists of the number of years of experience required.

I have tried to use regex which provides me the number of years but not the entire sentence.

def extract_years(self,resume_text):
 resume_text = str(resume_text.split('.'))
 exp=[]
 rx = re.compile(r"(\d+(?:-\d+)?\+?)\s*(years?)",re.I)

 for word in resume_text:
   exp_temp = rx.search(resume_text)

 if exp_temp:
   exp.append(exp_temp[0])
    
 exp = list(set(exp))
   
 return exp

Output: ['5-7 years']

Desired Output: ['5-7 years of experience in journalism, communications, or content creation preferred']

Upvotes: 1

Views: 144

Answers (1)

Angelo562
Angelo562

Reputation: 23

Try: (\d+(?:-\d+)?+?)\s*(years?).*

Though I'm somewhat new to Regex, I believe you can get what you desire using a combination of ".*" to end of your match terms and possibly the beginning if "5-7 years" comes after some characters like "needs 5-7 years of experience".

just adding the group ".*" at the end would mean to add any combination of characters, 0 or more after your initial match stopping at a line break, to match the entire sentence.
Hope this helps.

Upvotes: 1

Related Questions