Need to extract all digits from string

70 views
Skip to first unread message

Howard

unread,
Jul 27, 2021, 3:41:26 PM7/27/21
to BBEdit Talk
I have a string of numbers like this:

"12[11]4567[10]0"

The string may be longer or shorter than the one shown above. The numbers within the brackets always contain two digits.

I need to extract the numbers so they appear like below, each number a separate element. The format does not have to be vertical. I am just presenting it that way for readability. 

1
2
11
4
5
6
7
10
0

How can I do this using GREP and, if viable, 'regmatches'? 

Howard


Christopher Stone

unread,
Jul 27, 2021, 5:52:38 PM7/27/21
to BBEdit-Talk
Hey Howard,

What exactly do you mean by “regmatches”?

Find:

(\d|\[\d+\])

Replace:

\1\n

--
Best Regards,
Chris


Howard

unread,
Jul 28, 2021, 8:51:31 AM7/28/21
to BBEdit Talk
Regmatches is a term in R programming. Sorry if it caused confusion.

Tim A

unread,
Jul 29, 2021, 9:30:03 AM7/29/21
to BBEdit Talk

How to not include the brackets as Howard asked? I figure it involves non-capture but it eludes me.

Donald Goyette

unread,
Jul 29, 2021, 9:50:08 AM7/29/21
to BBEdit Talk

Find: (\d)|[(\d{2})]

Replace: \1\2\n (or just \1\2 if using "Extract")

Either \1 or \2 will be empty, so no harm in including both in the replacement.

On 29 Jul 2021, at 1:19, Tim A wrote:

Christopher Stone

unread,
Jul 29, 2021, 1:12:21 PM7/29/21
to BBEdit-Talk
On Jul 29, 2021, at 00:19, Tim A <timaa...@gmail.com> wrote:
How to not include the brackets as Howard asked? I figure it involves non-capture but it eludes me.


Eh?  Hmm. I must have been tired.

Find:

\[(\d+)\]|(\d)

Replace:

\1\2\n


--
Best Regards,
Chris

Reply all
Reply to author
Forward
0 new messages