Java regular expression needed to separate phone number and text in brackets
I'd like a regular expression for Java that can take this string
+1 7183541169 (East coast)
开发者_如何学编程And produce two groups
- +1 7183541169
- East coast
I'm having difficulty with escaping the round brackets.
Should be:
^(.*)\((.*)\)$
This assumes no special format - it will accept digits or letters anywhere. The regex reads:
^
- Start of the string
(.*)
- some letters (captured group)
\(
- literal (
(.*)
- more letters (captured group)
\)
- literal )
$
- end of string
Keep in mind it is a relatively easy task, and you can solve it with simple string manipulation.
/^(\+\d{1} \d+) \(((?:\w| |-)+)\)$/i
i don't know the rules for your string, but this should work.
精彩评论