# Regular Expression Question!

**URL:** <https://forum.freecodecamp.org/t/regular-expression-question/386192>\
**Category:** General\
**Created:** [May 9, 2020, 1:22pm UTC](https://forum.freecodecamp.org/t/regular-expression-question/386192 "2020-05-09T13:22:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eriyanto87](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eriyanto87/32/146506_2.png) [@eriyanto87](https://forum.freecodecamp.org/u/eriyanto87)\
**Post date:** [May 9, 2020, 1:22pm UTC](https://forum.freecodecamp.org/t/regular-expression-question/386192/1 "2020-05-09T13:22:46Z")

</div>

Hi All,

I’m doing these quizzes I found online so I can get more comfortable with REGEX. This particular problem is asking me to match these phone numbers:

```
415-555-1234
650-555-2345
  (416)555-3456
1 416 555 9292
4035555678
  202 555 4567

```

This is the solution:  
`1?[\s-]?\(?(\d{3})\)?[\s-]?\d{3}[\s-]?\d{4}`

I don’t understand what the second backslash before the parentheses is for?  
`1?` - to capture for one  
`[\s-]?` - to capture for dash or white space  
` \(?(\d{3})\)?` - I am asking about this backslash in the beginning to capture the area code.

When I remove it, the code didn’t work.

Will someone help me explain? I understand the rest of it.

Thanks in advance!!

---

<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:** [May 9, 2020, 1:25pm UTC](https://forum.freecodecamp.org/t/regular-expression-question/386192/2 "2020-05-09T13:25:21Z")

</div>

> [@eriyanto87](#):
>
> (?(\d{3}))? - I am asking about this backslash in the beginning to capture the area code.

Do you mean the `\d` symbol? `\d` is equivalent to `[0-9]`

---

<div class="post-metadata">

**Author:** ![eriyanto87](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eriyanto87/32/146506_2.png) [@eriyanto87](https://forum.freecodecamp.org/u/eriyanto87)\
**Post date:** [May 9, 2020, 1:29pm UTC](https://forum.freecodecamp.org/t/regular-expression-question/386192/3 "2020-05-09T13:29:59Z")

</div>

Hm i understand why the backslash disappears. Im talking about the backslash before the area code

 ![Screen Shot 2020-05-09 at 6.28.26 AM](https://global.discourse-cdn.com/freecodecamp/original/3X/1/8/182a5f32b244b8eb740ab53da6c2ec3ecb33da00.png)

---

<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:** [May 9, 2020, 1:32pm UTC](https://forum.freecodecamp.org/t/regular-expression-question/386192/4 "2020-05-09T13:32:35Z")

</div>

it is to escape the parenthesis, so it is a literal parenthesis and not the opening parenthesis of a capture group

* * *

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See [this post](http://www.freecodecamp.com/forum/t/forum-code-formatting/25574) to find the backtick on your keyboard. The “preformatted text” tool in the editor (`</>`) will also add backticks around text.

**Note:** Backticks are not single quotes.

![markdown_Forums](https://sea3.discourse-cdn.com/freecodecamp/uploads/default/original/3X/4/b/4b9a26f0c243380dd84935f4e29b92e3ecee8d05.gif)

---

<div class="post-metadata">

**Author:** ![eriyanto87](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eriyanto87/32/146506_2.png) [@eriyanto87](https://forum.freecodecamp.org/u/eriyanto87)\
**Post date:** [May 9, 2020, 1:37pm UTC](https://forum.freecodecamp.org/t/regular-expression-question/386192/5 "2020-05-09T13:37:07Z")

</div>

ah! I understand now. Thank you so much!

and thank you for editing my post and the tip on back ticks 🙂

---

<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:54pm UTC](https://forum.freecodecamp.org/t/regular-expression-question/386192/6 "2021-06-01T18:54:09Z")

</div>

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


