Question about Regular Expressions

Hello the assignment is to wrtie a regex that matches thoses strings and the answer above is the right answer. I don’t understand this part (?\d{3})? I don’t understand where the parentheses are and why. i tried without them and it does not work

Match these strings

  • :white_check_mark:718-555-3810
  • :white_check_mark:9175552849
  • :white_check_mark:1 212 555 3821
  • :white_check_mark:(917)5551298
  • :white_check_mark:212.555.8731

Is this from a lesson? It might help if you link it. The parentheses are used for “grouping” substrings together (I’m guessing this was covered in an earlier lesson, if not then that’s the term you want to search for).

Something about that regex is a little off (? should be a syntax error, it’s now the starting syntax for certain extensions (?: or (?= for example. Perhaps they should be escaped \( or something, trying to capture the literal ( and ) characters in the fourth string.

Edit: Just realised that they probably were escaped but were used as escapes in the formatted text on the forums so ignore the missing \( comments. I’m pretty sure the intention of that line is not grouping but actually matching a literal parenthesis (with a quantifier ofc).