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

Regex for pulling name out of pattern

I’m hoping to pull full names out of the following pattern. Some names have hyphens or multiple caps as the examples given:

(all numbers inside parentheses are either 1 or 2 digits). All Capitalized city abbreviations before parentheses are either 2 or 3 chars long)

Davante Adams LV (6)
Christian McCaffrey CAR (10)
J.K. Dobbins BAL (5)
Amon-Ra St. Brown DET (7)
AJ Brown PHI (11)
Michael Pittman Jr. IND (14)
JuJu Smith-Schuster PIT (9)

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

Results should be…

Davante Adams
Christian McCaffrey
J.K. Dobbins
Amon-Ra St. Brown
AJ Brown
Michael Pittman Jr.
JuJu Smith-Schuster

>Solution :

Using strsplit

strsplit(str, " [A-Z]+ \\(\\d+\\) *")[[1]]
#> [1] "Davante Adams"       "Christian McCaffrey" "J.K. Dobbins"       
#> [4] "Amon-Ra St. Brown"   "AJ Brown"            "Michael Pittman Jr."
#> [7] "JuJu Smith-Schuster"
``
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