0

Could you please tell me what is the Regex for (XXX) XXXXXXX in Java?

I have tried the below, however they seem to be wrong.

For example- (123) 4567890

String regex="/^(?:\(\d{3}\)|\d{3}-)\d{3}-\d{4}$/";

String regex = "\(\d{3}\)\d{3}-?\d{4}";

String regex ="^\(\d{3}\)\s\d{3}-\d{4}";

String regex = "(\A[0-9]{3}-[0-9]{3}-[0-9]{4}\z)";

Thanks, Ashley

Ashley
  • 19
  • 3

1 Answers1

0

If you are looking only for matching regex strictly for your example then something like below should match:

String regex = "^\\(\\d{3}\\) \\d{7}$";