# Reuse Patterns Using Capture Groups - Issue

**URL:** <https://forum.freecodecamp.org/t/reuse-patterns-using-capture-groups-issue/394954>\
**Category:** General\
**Created:** [May 27, 2020, 12:35pm UTC](https://forum.freecodecamp.org/t/reuse-patterns-using-capture-groups-issue/394954 "2020-05-27T12:35:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrPoque528](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/drpoque528/32/117735_2.png) [@DrPoque528](https://forum.freecodecamp.org/u/DrPoque528)\
**Post date:** [May 27, 2020, 12:35pm UTC](https://forum.freecodecamp.org/t/reuse-patterns-using-capture-groups-issue/394954/1 "2020-05-27T12:35:32Z")

</div>

Hi everyone,

I’m having a tough time understanding why the following code (which I got from trial and error) is passing:

> let reRegex = /^(\d+)(\s)\1\2\1$/;

From my understanding that Regex would work for anything in the following pattern:

> `"[word](space)[word]"`

And it would have to be explicitly that pattern because of the ^ at the beginning and the $ at the end.

However its passing 3 words with two spaces in between.  
e.g.

> “42 42 42”  
> "100 100 100

But not (as its 4 numbers)

> “42 42 42 42”

Can anyone explain why this pattern seems to pass?

Thanks!

---

<div class="post-metadata">

**Author:** ![snigo](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/snigo/32/128765_2.png) [@snigo](https://forum.freecodecamp.org/u/snigo)\
**Post date:** [May 27, 2020, 12:58pm UTC](https://forum.freecodecamp.org/t/reuse-patterns-using-capture-groups-issue/394954/2 "2020-05-27T12:58:47Z")

</div>

You regex is parsed in the following way:

```auto
^ : From start of the line
(\d+) : Match group (1st) of one or more digits
(\s) : Followed by a group (2nd) of whitespace character
\1 : Followed by whatever was captured in the first group
\2 : Followed by whatever was captured in the second group
\1 : Followed by whatever was captured in the first group
$ : Followed by the end of line

```

---

<div class="post-metadata">

**Author:** ![DrPoque528](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/drpoque528/32/117735_2.png) [@DrPoque528](https://forum.freecodecamp.org/u/DrPoque528)\
**Post date:** [May 27, 2020, 1:20pm UTC](https://forum.freecodecamp.org/t/reuse-patterns-using-capture-groups-issue/394954/3 "2020-05-27T13:20:44Z")

</div>

Ohhh I see

I didn’t realise the initial capture group declarations counted in addition to the backslash /1 & /2.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:51pm UTC](https://forum.freecodecamp.org/t/reuse-patterns-using-capture-groups-issue/394954/4 "2021-06-01T18:51:58Z")

</div>

Closed on June 1, 2021, 6:51pm UTC


