回答
/
^ <-- beginning of line
\(? <-- optional "("
([1-9]{1,3}) <-- 1, 2, or 3 digits (each between 1 and 9)
\)?? <-- optional ")" (matches the first close parenthesis if multiple are present in the string)
([0-9]{9}) <-- 9 digits (each between 0 and 9)
$ <-- end of line
/
这似乎符合其通过在一个区域/国家代码
+1认为以图像形式呈现将给出清晰的想法,但我喜欢这样。 – Praveen
为了简单,我只是上传这个图片(来自http://www.regexper.com/#%2F%5E%5C(%3F(%5B1-9%5D%7B1%2C3%7D)%5C)%3F%3F(%5B0-9%5D%7B9%7D)%24%2F)
这张照片本身并不是不言自明的 – SheetJS
+1 @Nirk,我认为这是非常清楚的。 –
见前缀的电话号码这种自由间隔模式。我假设你正在使用PCRE
/^ #match the beginning of the string
\(? #match literal (, if exists
( #group 1
[1-9]{1,3} #match one, two, or three digit(s). The digit must be between 1-9
) #end of group1
\)?? #match literal), if exists
( #group 2
[0-9]{9} #match 9 digits, 0-9
) #end of group2
$/ #match the end of the string
- 1. regexp freebie ...我该怎么做?
- 2. 它为什么有3个错误?我做了什么错误?
- 3. 此RegExp有什么问题?
- 4. DateTime.ParseExact没有做什么,我想要它做的
- 5. random.seed():它做什么?
- 6. HttpWebRequest.UserAgent:它做什么
- 7. pushViewController什么都不做,当我叫它
- 8. Google Web Toolkit,我能用它做什么?
- 9. psn参数。我能用它做什么?
- 10. 做这个代码做我需要它做什么
- 11. 什么是MD5CryptoServiceProvider,它可以做什么?
- 12. 什么是web.xml文件,我可以用它做什么?
- 13. EntityManager.flush是做什么的,为什么我需要使用它?
- 14. GLEW是做什么的,为什么我需要它?
- 15. CustomNSError协议做了什么,我为什么要采用它?
- 16. 它什么也不做
- 17. 递归 - 它做什么
- 18. iOS:UIButton titleLabel - 它什么都做?
- 19. Zend url()...它在做什么?
- 20. struct和:: - 它做什么
- 21. sortedArrayUsingSelector它在做什么?
- 22. HierarchicalDataTemplate它应该做什么?
- 23. 它为什么叫做nillable?
- 24. Foo.class它做了什么?
- 25. Python:kernel32.CreateProcessA()它在做什么?
- 26. Numpy argsort - 它在做什么?
- 27. PowerShell的“ResumeState”它做什么
- 28. in()...它是做什么的?
- 29. 我有一些Actionscript代码;它会做什么?
- 30. 这个RegExp有什么问题?
http://www.regexper.com/#%2F%5E%5C(%3F(%5B1-9%5D%7B1%2C3%7D)%5C) %3F%3F(%5B0-9%5D%7B9%7D)%24%2F – SheetJS