find first x of a ',' delimited set of numeric strings?

17 views
Skip to first unread message

Joel Braverman

unread,
Apr 26, 2021, 1:59:02 PM4/26/21
to BBEdit Talk
have a few thousand of these: 
'199','627','1151','1249','1557','1558','1565','1689','1693','1711','1770','1780'

I want to break them up into subgroups as our SQL system chokes at > 4000 items in a query.  How do I do that? I found a regex:

[^,\\w][^\\,]*[^,]

which seems to find all items, but now I need to extract the first 4000.

 - Joel

Tom Robinson

unread,
Apr 26, 2021, 5:59:55 PM4/26/21
to BBEdit Talk
This breaks the items into groups of 3 — look for anything which isn’t a comma, followed by a comma, repeat 3 times.

Find:  ([^,]*,){3}
Replace:  &\r


This drops everything after the first 3 items (needs a tweak to remove trailing comma) — as above but also capture rest of line, and replace with first group.

Find:  (([^,]*,){3}).+
Replace:  \1

Cheers

Christopher Stone

unread,
Apr 27, 2021, 7:20:29 AM4/27/21
to BBEdit-Talk
On 04/26/2021, at 12:53, Joel Braverman <joelj...@gmail.com> wrote:
have a few thousand of these: 
'199','627','1151','1249','1557','1558','1565','1689','1693','1711','1770','1780'

I want to break them up into subgroups as our SQL system chokes at > 4000 items in a query.


Hey Joel,

Find:

(?:'[^']+',){4000}

Replace:

&\n

Since you're dealing with pretty big chunks of data, I'd turn capturing off with (?: as above.

--
Best Regards,
Chris

Reply all
Reply to author
Forward
0 new messages