This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
I'm trying to extract the first 5 words after a key word. I've used a simple regex to get everything after a key word - (replac)(.*) - but I'd like to narrow it down to up to the first 5 words (names range from 2 to 5 words). for example:
replace John L. Robert Smith Jr. as the new agent etc....
Note: punctuation isn't always there.
Also, sometimes the key word could be replace, replaced or replacing ...that's why I used (replac) ...I know there must be a way to put each variable in but not sure how.
Until I get them to regulate how the data is input I don't have a choice. The best I can do then is to request the first 5 words after replace, replacing or replaced. This will narrow things down in the interim that I can do some fuzzy matching afterward to make comparisons.
With that in mind what is best regex for that then to pull just the first five words regardless of case?
Unfortunately it doesn't if the name is all upper case.
I apologize; in trying to simplify my question it ultimately left too much for assumption.
Here is a better example of what my strings may look like:
Leilani Hernandez (TP60857), 5/9/2019 6:12:56 PM ET: Per owner request replacedLAURA JEAN TEBLAY 423931/cm 35827011 (100%) with ROGER A SEIM 582245/cm 758 1798
Tracy McCarthy (cr54196), 4/29/2019 2:37:09 PM ET: Received block transfer request from agency 002 replacingManny Alfonso 811794 / 702 0103.0; 702 0103.1 with Wendy Jennings 240716 / 702 0104.0 See reassignment tracking under ID 411794
Peter Martin (JJ82609), 7/8/2019 11:16:41 AM ET: Per Agency request, replaceJONATHAN TYLER 609103 (50% -S) and SANDRA RODRIGUEZ (50%) with JOHN JOHNSON 599578 (100%)
From this I would like to extract the name (which is sometimes all caps or not) after key words "replace" or "replaced" or "replacing".
Results to look like this:
Laura Jean Teblay
Again, sorry for not being clearer initially...your time and help is appreciated!
Since it looks like @Thableaus has stepped out for a minute, i'll offer up a solution.
Your actual data is much better than the mock-ups that you originally provided. With them we can see the end delimiter for the names is actually a series of digits. This regex formula should work if your data always has these