Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use REGEXTRACT to extract certain characters between two strings

I am trying to extract a person’s name between different characters. For example, the cells contains this information

PATIENT: 2029985 - COLLINS, JUNIOR .
PATIENT: 1235231-02 - JERRY JR, PATRICK .
PATIENT: 986435--EXP-- - JULIUS, DANIEL .
PATIENT: 2021118-02 - DRED-HARRY, KEVIN .

My goal is to use one REGEXTRACT formula to get the following:

COLLINS, JUNIOR
JERRY JR, PATRICK
JULIUS, DANIEL
LOVE ALSTON, BRENDA

So far, I have come up with the formula:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

=ARRAYFORMULA(REGEXEXTRACT(B3:B, "-(.*)\."))

Where B3 contains the first information

Using that formula, I get:

COLLINS, JUNIOR
02 - JERRY JR, PATRICK
02 - LOVE-ALSTON, BRENDA 
-EXP-- - JULIUS, DANIEL
02 - DRED-HARRY, KEVIN

I managed to get the first name down but how do I go about extracting the rest.

>Solution :

You can use

=ARRAYFORMULA(REGEXEXTRACT(B3:B, "\s-\s+([^.]*?)\s*\."))

See the regex demo. Details:

  • \s-\s+ – a whitespace, -, one or more whitespaces
  • ([^.]*?) – Group 1: zero or more chars other than a . as few as possible
  • \s* – zero or more whitespaces
  • \. – a . char.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading