Skip to main content
dublove
Legend
June 2, 2025
Answered

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

  • June 2, 2025
  • 2 replies
  • 359 views
((^\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.

Correct answer m1b

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

2 replies

Frans v.d. Geest
Community Expert
Community Expert
June 2, 2025

Count the brackets ()      😉

m1b
Community Expert
Community Expert
June 2, 2025

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. 

dublove
dubloveAuthor
Legend
June 2, 2025

One bracket captured once?

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
June 2, 2025

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