Using RegExp to match parentheses with set number of characters inside

Viewed 512

I am trying to write a regular expression which will match the brackets of (555) in 1 (555) 555-5555 and replace the brackets with nothing. However, there should be not match if there is only one parenthesis, such as in this, 1 555)555-5555 or if there is more than three numbers/characters inside the parentheses such as in (6505552368).

My best attempt seemed to be this

re = /\((?=.{3})/;

But it would only match and replace the first parenthesis, which wasn't much help. Would appreciate any ideas.

4 Answers
Related