Test, validate and match regular expressions
Matches US phone numbers in a wide variety of formats, including an optional country code (+1 or 1), an optional area code either in parentheses or separated by spaces, periods, slashes, or dashes, and an optional extension like x1234. Supports formats such as 555-123-4567, (555) 123-4567, +1 555.123.4567, and 5551234567. Uses conditionals to ensure parentheses stay balanced. Useful for validating or extracting phone numbers from text.