Skip to main content
dublove
Legend
Jun 2, 2025 7:56 AM UTC
Answered

How do you understand that ((^\s)*)(abc) has 3 groups and abc is $3?

((^\s)*)(abc)

I originally thought that with one set of brackets, abc should be $2.
But in fact, abc is $3

 

But the expression:

([,,\h]*)(abc) 

Here abc is $2.

m1b
m1bCorrect answer
Community Expert
Jun 2, 2025 10:22 AM UTC

Well, yes, once for each found instance.

 

Try this experiment, using text frame with "abcdefghijklmnopqrstuvwxyz".

1. findWhat: 

(abc)(def(ghi)jkl)(mno)

2. changeTo:

0 = $0\r1 = $1\r2 = $2\r3= $3\r4 = $4\r\rnot captured = 

 

So start with this: 

 

Then perform the find/change on the text. You will see this:

 

We have split up the capture groups and shown them with the index. Maybe it will help you to look carefully at what is going on here, especially the nested group that captures "ghi".

- Mark

5 replies

Frans v.d. Geest
Community Expert
Community Expert
Jun 2, 2025 10:04 AM UTC

Count the brackets ()      😉

Translate
m1b
Community Expert
Community Expert
Jun 2, 2025 8:53 AM UTC

You have 3 capture groups. (ABC) is the third.

 

if you're not sure, just count the "(" from the left ... 1, 2, 3!

 

P.S. in your second example you have 2 capture groups and (abc) is the second. 

Translate
dublove
dubloveAuthor
Legend
Jun 2, 2025 10:04 AM UTC

One bracket captured once?

Translate
m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
Jun 2, 2025 10:22 AM UTC

Well, yes, once for each found instance.

 

Try this experiment, using text frame with "abcdefghijklmnopqrstuvwxyz".

1. findWhat: 

(abc)(def(ghi)jkl)(mno)

2. changeTo:

0 = $0\r1 = $1\r2 = $2\r3= $3\r4 = $4\r\rnot captured = 

 

So start with this: 

 

Then perform the find/change on the text. You will see this:

 

We have split up the capture groups and shown them with the index. Maybe it will help you to look carefully at what is going on here, especially the nested group that captures "ghi".

- Mark

Translate