{"action":"created","comment":{"url":"https://api.github.com/repos/brson/rust-cookbook/pulls/comments/128828581","pull_request_review_id":51548960,"id":128828581,"diff_hunk":"@@ -470,6 +471,80 @@ fn main() {\n }\n ```\n \n+[ex-phone]: #ex-phone\n+<a name=\"ex-phone\"></a>\n+## Extract phone numbers from text\n+\n+Attempts to process a static string as a list including US phone numbers.  The\n+expression is checking that there are 7 digits that come in groups of 3 3 4,\n+separated by spaces, dots, dashes, and parenthesis.  The phone number is then\n+tested based on formatting rules.\n+\n+```rust\n+# #[macro_use]\n+# extern crate error_chain;\n+extern crate regex;\n+\n+use regex::Regex;\n+use std::fmt;\n+\n+# error_chain!{\n+#     foreign_links {\n+#         Regex(regex::Error);\n+#         Io(std::io::Error);\n+#     }\n+# }\n+#\n+struct PhoneNumber {\n+    country: String,\n+    number: String,\n+}\n+\n+// This allows printing phone numbers based on country convention.\n+impl fmt::Display for PhoneNumber {\n+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {\n+        match self.country.as_ref() {\n+            \"US\" => write!(f, \"+1 ({}) {}-{}\", &self.number[0..3], &self.number[3..6], &self.number[6..10]),\n+            _    => write!(f, \"{}\", self.number),\n+        }\n+    }\n+}\n+\n+fn run() -> Result<()> {\n+    let phone_text = \"\n+    +1 505 881 9292\n+    (202) 991 9534\n+    Alex 5553920011\n+    1 (800) 233-2010\n+    1.299.339.1020\";\n+    let re = Regex::new(r\"(?x)\n+                         \\+?1?                      #Country Code Optional\n+                         [\\x20\\(\\.]*\n+                         ([2-9]\\d{2})               #Area Code\n+                         [\\x20\\)\\.\\-]*\n+                         ([2-9]\\d{2})               #Exchange Code\n+                         [\\x20\\.\\-]*\n+                         (\\d{4})                    #Subscriber Number\")?;\n+    let mut phone_numbers = re.captures_iter(phone_text).map(|cap| {\n+        PhoneNumber {\n+            country: \"US\".to_owned(),","path":"src/basics.md","position":68,"original_position":68,"commit_id":"b04fe5b1322304fb58516cd0451a6a9eae8a613d","original_commit_id":"b04fe5b1322304fb58516cd0451a6a9eae8a613d","user":{"login":"budziq","id":221000,"avatar_url":"https://avatars2.githubusercontent.com/u/221000?v=4","gravatar_id":"","url":"https://api.github.com/users/budziq","html_url":"https://github.com/budziq","followers_url":"https://api.github.com/users/budziq/followers","following_url":"https://api.github.com/users/budziq/following{/other_user}","gists_url":"https://api.github.com/users/budziq/gists{/gist_id}","starred_url":"https://api.github.com/users/budziq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/budziq/subscriptions","organizations_url":"https://api.github.com/users/budziq/orgs","repos_url":"https://api.github.com/users/budziq/repos","events_url":"https://api.github.com/users/budziq/events{/privacy}","received_events_url":"https://api.github.com/users/budziq/received_events","type":"User","site_admin":false},"body":"the country does not make much sense here as its unconditionally \"US\" maybe lets just drop it (also using String as a match tag would not be a best idea).\r\n\r\nhow about storing area exchange and subscriber codes separately instead?","created_at":"2017-07-21T18:21:03Z","updated_at":"2017-07-21T18:43:33Z","html_url":"https://github.com/brson/rust-cookbook/pull/252#discussion_r128828581","pull_request_url":"https://api.github.com/repos/brson/rust-cookbook/pulls/252","_links":{"self":{"href":"https://api.github.com/repos/brson/rust-cookbook/pulls/comments/128828581"},"html":{"href":"https://github.com/brson/rust-cookbook/pull/252#discussion_r128828581"},"pull_request":{"href":"https://api.github.com/repos/brson/rust-cookbook/pulls/252"}}},"pull_request":{"url":"https://api.github.com/repos/brson/rust-cookbook/pulls/252","id":131427305,"html_url":"https://github.com/brson/rust-cookbook/pull/252","diff_url":"https://github.com/brson/rust-cookbook/pull/252.diff","patch_url":"https://github.com/brson/rust-cookbook/pull/252.patch","issue_url":"https://api.github.com/repos/brson/rust-cookbook/issues/252","number":252,"state":"open","locked":false,"title":"Extract phone numbers from text","user":{"login":"AndyGauge","id":6525150,"avatar_url":"https://avatars1.githubusercontent.com/u/6525150?v=4","gravatar_id":"","url":"https://api.github.com/users/AndyGauge","html_url":"https://github.com/AndyGauge","followers_url":"https://api.github.com/users/AndyGauge/followers","following_url":"https://api.github.com/users/AndyGauge/following{/other_user}","gists_url":"https://api.github.com/users/AndyGauge/gists{/gist_id}","starred_url":"https://api.github.com/users/AndyGauge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndyGauge/subscriptions","organizations_url":"https://api.github.com/users/AndyGauge/orgs","repos_url":"https://api.github.com/users/AndyGauge/repos","events_url":"https://api.github.com/users/AndyGauge/events{/privacy}","received_events_url":"https://api.github.com/users/AndyGauge/received_events","type":"User","site_admin":false},"body":"Fixes #241 ","created_at":"2017-07-19T21:46:21Z","updated_at":"2017-07-21T18:43:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4d29d9ed4fb4a9b802808d11d1a02b07025759d5","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/brson/rust-cookbook/pulls/252/commits","review_comments_url":"https://api.github.com/repos/brson/rust-cookbook/pulls/252/comments","review_comment_url":"https://api.github.com/repos/brson/rust-cookbook/pulls/comments{/number}","comments_url":"https://api.github.com/repos/brson/rust-cookbook/issues/252/comments","statuses_url":"https://api.github.com/repos/brson/rust-cookbook/statuses/b04fe5b1322304fb58516cd0451a6a9eae8a613d","head":{"label":"AndyGauge:ex-phone","ref":"ex-phone","sha":"b04fe5b1322304fb58516cd0451a6a9eae8a613d","user":{"login":"AndyGauge","id":6525150,"avatar_url":"https://avatars1.githubusercontent.com/u/6525150?v=4","gravatar_id":"","url":"https://api.github.com/users/AndyGauge","html_url":"https://github.com/AndyGauge","followers_url":"https://api.github.com/users/AndyGauge/followers","following_url":"https://api.github.com/users/AndyGauge/following{/other_user}","gists_url":"https://api.github.com/users/AndyGauge/gists{/gist_id}","starred_url":"https://api.github.com/users/AndyGauge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndyGauge/subscriptions","organizations_url":"https://api.github.com/users/AndyGauge/orgs","repos_url":"https://api.github.com/users/AndyGauge/repos","events_url":"https://api.github.com/users/AndyGauge/events{/privacy}","received_events_url":"https://api.github.com/users/AndyGauge/received_events","type":"User","site_admin":false},"repo":{"id":91820660,"name":"rust-cookbook","full_name":"AndyGauge/rust-cookbook","owner":{"login":"AndyGauge","id":6525150,"avatar_url":"https://avatars1.githubusercontent.com/u/6525150?v=4","gravatar_id":"","url":"https://api.github.com/users/AndyGauge","html_url":"https://github.com/AndyGauge","followers_url":"https://api.github.com/users/AndyGauge/followers","following_url":"https://api.github.com/users/AndyGauge/following{/other_user}","gists_url":"https://api.github.com/users/AndyGauge/gists{/gist_id}","starred_url":"https://api.github.com/users/AndyGauge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndyGauge/subscriptions","organizations_url":"https://api.github.com/users/AndyGauge/orgs","repos_url":"https://api.github.com/users/AndyGauge/repos","events_url":"https://api.github.com/users/AndyGauge/events{/privacy}","received_events_url":"https://api.github.com/users/AndyGauge/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/AndyGauge/rust-cookbook","description":null,"fork":true,"url":"https://api.github.com/repos/AndyGauge/rust-cookbook","forks_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/forks","keys_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/teams","hooks_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/hooks","issue_events_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/issues/events{/number}","events_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/events","assignees_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/assignees{/user}","branches_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/branches{/branch}","tags_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/tags","blobs_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/git/refs{/sha}","trees_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/statuses/{sha}","languages_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/languages","stargazers_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/stargazers","contributors_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/contributors","subscribers_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/subscribers","subscription_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/subscription","commits_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/commits{/sha}","git_commits_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/git/commits{/sha}","comments_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/comments{/number}","issue_comment_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/issues/comments{/number}","contents_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/contents/{+path}","compare_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/merges","archive_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/downloads","issues_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/issues{/number}","pulls_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/pulls{/number}","milestones_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/milestones{/number}","notifications_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/labels{/name}","releases_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/releases{/id}","deployments_url":"https://api.github.com/repos/AndyGauge/rust-cookbook/deployments","created_at":"2017-05-19T15:37:13Z","updated_at":"2017-05-19T15:37:14Z","pushed_at":"2017-07-21T17:42:08Z","git_url":"git://github.com/AndyGauge/rust-cookbook.git","ssh_url":"git@github.com:AndyGauge/rust-cookbook.git","clone_url":"https://github.com/AndyGauge/rust-cookbook.git","svn_url":"https://github.com/AndyGauge/rust-cookbook","homepage":"https://brson.github.io/rust-cookbook","size":1013,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"brson:master","ref":"master","sha":"fad366bca4672d19fd34cc7a5e7fc82e2b09c528","user":{"login":"brson","id":147214,"avatar_url":"https://avatars0.githubusercontent.com/u/147214?v=4","gravatar_id":"","url":"https://api.github.com/users/brson","html_url":"https://github.com/brson","followers_url":"https://api.github.com/users/brson/followers","following_url":"https://api.github.com/users/brson/following{/other_user}","gists_url":"https://api.github.com/users/brson/gists{/gist_id}","starred_url":"https://api.github.com/users/brson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brson/subscriptions","organizations_url":"https://api.github.com/users/brson/orgs","repos_url":"https://api.github.com/users/brson/repos","events_url":"https://api.github.com/users/brson/events{/privacy}","received_events_url":"https://api.github.com/users/brson/received_events","type":"User","site_admin":false},"repo":{"id":82722984,"name":"rust-cookbook","full_name":"brson/rust-cookbook","owner":{"login":"brson","id":147214,"avatar_url":"https://avatars0.githubusercontent.com/u/147214?v=4","gravatar_id":"","url":"https://api.github.com/users/brson","html_url":"https://github.com/brson","followers_url":"https://api.github.com/users/brson/followers","following_url":"https://api.github.com/users/brson/following{/other_user}","gists_url":"https://api.github.com/users/brson/gists{/gist_id}","starred_url":"https://api.github.com/users/brson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brson/subscriptions","organizations_url":"https://api.github.com/users/brson/orgs","repos_url":"https://api.github.com/users/brson/repos","events_url":"https://api.github.com/users/brson/events{/privacy}","received_events_url":"https://api.github.com/users/brson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brson/rust-cookbook","description":null,"fork":false,"url":"https://api.github.com/repos/brson/rust-cookbook","forks_url":"https://api.github.com/repos/brson/rust-cookbook/forks","keys_url":"https://api.github.com/repos/brson/rust-cookbook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brson/rust-cookbook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brson/rust-cookbook/teams","hooks_url":"https://api.github.com/repos/brson/rust-cookbook/hooks","issue_events_url":"https://api.github.com/repos/brson/rust-cookbook/issues/events{/number}","events_url":"https://api.github.com/repos/brson/rust-cookbook/events","assignees_url":"https://api.github.com/repos/brson/rust-cookbook/assignees{/user}","branches_url":"https://api.github.com/repos/brson/rust-cookbook/branches{/branch}","tags_url":"https://api.github.com/repos/brson/rust-cookbook/tags","blobs_url":"https://api.github.com/repos/brson/rust-cookbook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brson/rust-cookbook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brson/rust-cookbook/git/refs{/sha}","trees_url":"https://api.github.com/repos/brson/rust-cookbook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brson/rust-cookbook/statuses/{sha}","languages_url":"https://api.github.com/repos/brson/rust-cookbook/languages","stargazers_url":"https://api.github.com/repos/brson/rust-cookbook/stargazers","contributors_url":"https://api.github.com/repos/brson/rust-cookbook/contributors","subscribers_url":"https://api.github.com/repos/brson/rust-cookbook/subscribers","subscription_url":"https://api.github.com/repos/brson/rust-cookbook/subscription","commits_url":"https://api.github.com/repos/brson/rust-cookbook/commits{/sha}","git_commits_url":"https://api.github.com/repos/brson/rust-cookbook/git/commits{/sha}","comments_url":"https://api.github.com/repos/brson/rust-cookbook/comments{/number}","issue_comment_url":"https://api.github.com/repos/brson/rust-cookbook/issues/comments{/number}","contents_url":"https://api.github.com/repos/brson/rust-cookbook/contents/{+path}","compare_url":"https://api.github.com/repos/brson/rust-cookbook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brson/rust-cookbook/merges","archive_url":"https://api.github.com/repos/brson/rust-cookbook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brson/rust-cookbook/downloads","issues_url":"https://api.github.com/repos/brson/rust-cookbook/issues{/number}","pulls_url":"https://api.github.com/repos/brson/rust-cookbook/pulls{/number}","milestones_url":"https://api.github.com/repos/brson/rust-cookbook/milestones{/number}","notifications_url":"https://api.github.com/repos/brson/rust-cookbook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brson/rust-cookbook/labels{/name}","releases_url":"https://api.github.com/repos/brson/rust-cookbook/releases{/id}","deployments_url":"https://api.github.com/repos/brson/rust-cookbook/deployments","created_at":"2017-02-21T20:17:58Z","updated_at":"2017-07-21T17:55:29Z","pushed_at":"2017-07-21T17:42:10Z","git_url":"git://github.com/brson/rust-cookbook.git","ssh_url":"git@github.com:brson/rust-cookbook.git","clone_url":"https://github.com/brson/rust-cookbook.git","svn_url":"https://github.com/brson/rust-cookbook","homepage":"https://brson.github.io/rust-cookbook","size":1046,"stargazers_count":261,"watchers_count":261,"language":"CSS","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":61,"mirror_url":null,"open_issues_count":57,"forks":61,"open_issues":57,"watchers":261,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/brson/rust-cookbook/pulls/252"},"html":{"href":"https://github.com/brson/rust-cookbook/pull/252"},"issue":{"href":"https://api.github.com/repos/brson/rust-cookbook/issues/252"},"comments":{"href":"https://api.github.com/repos/brson/rust-cookbook/issues/252/comments"},"review_comments":{"href":"https://api.github.com/repos/brson/rust-cookbook/pulls/252/comments"},"review_comment":{"href":"https://api.github.com/repos/brson/rust-cookbook/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/brson/rust-cookbook/pulls/252/commits"},"statuses":{"href":"https://api.github.com/repos/brson/rust-cookbook/statuses/b04fe5b1322304fb58516cd0451a6a9eae8a613d"}}}}
{"actor":{"display_login":"budziq"}}