Using GREP, need help to extract names and numbers from column

40 views
Skip to first unread message

Howard

unread,
Feb 9, 2022, 4:42:41 PM2/9/22
to BBEdit Talk
I have a column with data like this, where each name contains just the first initial, a period, and the last name:

D.Green (59-72) and B.Valentine (12-19)
D.Green (69-75)
D.Green (55-58)
J.Torborg (13-25) and D.Green (46-78)
J.Torborg (72-90)
B.Harrelson (74-80) and M.Cubbage (3-4)
D.Johnson (20-22) and B.Harrelson (71-49)
D.Johnson (87-75)

Some rows have one name and a pair of numbers in parentheses separated by a dash, and some rows have two names, each followed by a pair of numbers in parentheses separated by a dash.

In each row, I can extract the first name (both the initial and the last name) and put a space between them using `^([A-Z]\.)([A-z,a-z]+)` and `\1 \2`
with all results appearing in their own column.

What I need help to do is this:
1. Using GREP, I need to extract the numbers in parentheses after the first names and put them in their own column without parentheses.
59-72
69-75
55-58 etc.

2. In those rows with a second name, using GREP I need to extract the second names and put them in their own column, so they look like this:
B. Valentine
D. Green
M. Cubbage
B. Harrelson 

I also need to extract the numbers in parentheses after the second names, but believe that I can figure out how to do that from the answer to #1 above.

Thanks,
Howard

jj

unread,
Feb 10, 2022, 4:31:26 AM2/10/22
to BBEdit Talk
Hi Howard,

You could try this to get tab separated fields:

Find:

    (\S+\.)(\S+)\h*\((\d+-\d+)\)\h*(?:and\h*(\S+\.)(\S+)\h*\((\d+-\d+)\))?
   
Replace:

    \1 \2\t\3\t\4 \5\t\6
   
HTH,

Jean Jourdain

David G Wagner

unread,
Feb 10, 2022, 8:31:38 AM2/10/22
to BBEdit Talk
I took the data and tried this:

([a-z]\.)([a-z]+)\s+\(([^\)]+)\)(\s*(and){0,1}\s*)

Replace as

\1\2\t\3\n

You stated an extra column needed, so used \t (tab inserted). This did your test data in one pass. 

Wags ;)
WagsWorld
Hebrews 4:15
Ph(primary) : 408-914-1341
Ph(secondary): 408-761-7391
--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/e3034738-5b73-4c3b-a016-7a88615d5f54n%40googlegroups.com.

Howard

unread,
Feb 10, 2022, 4:44:59 PM2/10/22
to BBEdit Talk
Jean,

Your solution does what I need. 

Thanks,
Howard

Howard

unread,
Feb 10, 2022, 4:49:35 PM2/10/22
to BBEdit Talk
Wags,

I appreciate what you did. Your solution is helpful.

Howard

Reply all
Reply to author
Forward
0 new messages