Reuse Patterns Using Capture Groups how?

I need someone to explain this answer to me because I don’t understand how it works and I don’t feel the explanation on the page is particularly clear. The number part I just don’t get.

I got this far:

/(\d+)\s\1/

but the answer is:

/^(\d+)\s\1\s\1$/;

How does it check three times? Why can’t you do:

/(\d+\s)\1\1/;

that last one, you need an extra space at the end so it can’t work

in the first one you match two consecutive numbers, not three

I’m sorry I don’t follow what do you mean?

this one has a space in the capture group so it’s like /(\d+\s)(\d+\s)(\d+\s)/, it doesn’t match something like "32 32 32" because this regex is searching for an extra space at the end

this one is like /(\d+)\s(\d+)/, it matches "32 32" which should not be matched as it is too short

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.