Description
You provided the following examples of numbers you'd like matched.
+4454475294x364
+44 544-75294 x364
(123) 555-1212x4567
123-555-1232
The Regex
This regex will do the following:
- Match international numbers of the format you provided
- Match North American numbers
- If the phone number is followed by an extension, then capture that
- Allow spaces, hyphens, and parentheses at obvious spots
- This is limited to just the formats that you listed in your question
^(?:[+][0-9]{2}\s?[0-9]{3}[-]?[0-9]{3,}|(?:[(][0-9]{3}[)]|[0-9]{3})\s*[-]?\s*[0-9]{3}[-][0-9]{4})(?:\s*x\s*[0-9]+)?
Note: for Java you'll need to escape the forward slashes \
to look like \\
.
Explanation

NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of a "line"
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
[+] any character of: '+'
----------------------------------------------------------------------
[0-9]{2} any character of: '0' to '9' (2 times)
----------------------------------------------------------------------
\s? whitespace (\n, \r, \t, \f, and " ")
(optional (matching the most amount
possible))
----------------------------------------------------------------------
[0-9]{3} any character of: '0' to '9' (3 times)
----------------------------------------------------------------------
[-]? any character of: '-' (optional
(matching the most amount possible))
----------------------------------------------------------------------
[0-9]{3,} any character of: '0' to '9' (at least 3
times (matching the most amount
possible))
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
[(] any character of: '('
----------------------------------------------------------------------
[0-9]{3} any character of: '0' to '9' (3 times)
----------------------------------------------------------------------
[)] any character of: ')'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[0-9]{3} any character of: '0' to '9' (3 times)
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
[-]? any character of: '-' (optional
(matching the most amount possible))
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
[0-9]{3} any character of: '0' to '9' (3 times)
----------------------------------------------------------------------
[-] any character of: '-'
----------------------------------------------------------------------
[0-9]{4} any character of: '0' to '9' (4 times)
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
(?: group, but do not capture (optional
(matching the most amount possible)):
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
x 'x'
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
[0-9]+ any character of: '0' to '9' (1 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
)? end of grouping
Examples
Using the sample text above
Matches
[0][0] = +4454475294x364
[1][0] = +44 544-75294 x364
[2][0] = (123) 555-1212x4567
[3][0] = 123-555-1232