Have trouble understanding capturing groups and back references

\d is just one digit.

This regular expression doesn't match the "123-456-7890" string but it would match "323" (which could be part of a greater string, for example "323-456-7890") :

 (\d) : first digit ("3")
 \d   : another digit ("2")
 \1   : first group (which was "3")

Now, if your book pretends that (\d)\d\1 should capture "123" in "123-456-7890", then it might contain an error...


(\d)\d\1 step by step:

  1. The first \d matches one digit
  2. And the parentheses () mark this as a capturing group - this is the first one, so the digit is remembered as "group 1"
  3. The second \d says there is another digit
  4. \1 says "here is the value from our previous group 1" - that is the digit that was matched in step 1.

So like dystroy already said: the regex should match a sequence of three digits of which the first and the third are equal.