Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
From resume text, I want to extract the number of years of experience of a candidate.

How I intended on obtaining this-->
Years of experience is usually mentioned as '4 Years' or '6+ years' or '4.8 year'.

What I have tried:

exp_p='[^\d]*(\d*\+? years|Years|year|Year)'


Expected Output-
'x years'


I'm getting the expected output only when the experience number is follwed by "years".


This expression works only for the first word in the series of 'or' conditions, i.e., "years" in this context. Why isn't the 'or' operator working as expecting?
Posted
Updated 18-Sep-22 5:44am
Comments
Richard MacCutchan 18-Sep-22 10:53am    
Try this:
\d*\.?\d*\+?\s+(?:[Yy]ears|[Yy]ear)
Apoorva 2022 19-Sep-22 6:08am    
Thank you. It works.

1 solution

Instead of
Python
exp_p='[^\d]*(\d*\+? years|Years|year|Year)'

Try
Python
exp_p='\d+(\.\d+)\s*(years|Years|year|Year)'


Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]
 
Share this answer
 
Comments
Richard MacCutchan 18-Sep-22 11:49am    
You do not need the 's' at the end of Year or year.
Patrice T 18-Sep-22 11:54am    
In question, the 's' is part of the output.
Richard MacCutchan 18-Sep-22 11:55am    
Oops - my apologies.
Apoorva 2022 19-Sep-22 6:10am    
Thanks for the resources.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900