开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜