Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added verify email and extract login example #249

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
2 participants
@Ophirr33
Copy link
Contributor

Ophirr33 commented Jul 15, 2017

Fixes #240. Verifies that the text looks like an email address (anything that's not white space or an @, followed by an @, followed by period joined sequences of word characters).

@budziq

This comment has been minimized.

Copy link
Collaborator

budziq commented Jul 15, 2017

Hi @Ophirr33 thanks for all the submissions!

Unfortunately I'll not be able to follow up with anything resembling review for the next two weeks due to holidays 😞 . I may drop some comments when Im on mobile later and I've asked other maintainers to drop from time to time and look into the PR's.

@Ophirr33

This comment has been minimized.

Copy link
Contributor Author

Ophirr33 commented Jul 16, 2017

@budziq No worries!

@budziq
Copy link
Collaborator

budziq left a comment

Hi @Ophirr33. Nice work :).
Just some comments from mobile to make the next reviewers life easier.

Validates that an email address is formatted correctly, and extracts everything
before the @ symbol.

```rust,no_run

This comment has been minimized.

@budziq

budziq Jul 16, 2017

Collaborator

no reason to make the example no_run


```rust,no_run
extern crate regex;
use regex::Regex;

This comment has been minimized.

@budziq

budziq Jul 16, 2017

Collaborator

please add a newline between extern and use

use regex::Regex;
// A simple email validator and extractor. Validates that something has an @
// symbol, followed by something that looks like a domain.

This comment has been minimized.

@budziq

budziq Jul 16, 2017

Collaborator

I would suggest to move such descriptions to top with rest of the text. Also I would try to keep the comments as brief as possible (or even get rid of them in favour of textual description above) as we do not try to teach regular expressions here just show off the crate and snippet.

// A simple email validator and extractor. Validates that something has an @
// symbol, followed by something that looks like a domain.
// Returns what came before the @ symbol if everything looks valid.
fn extract_login(input: &str) -> Option<String> {

This comment has been minimized.

@budziq

budziq Jul 16, 2017

Collaborator
  • Option<Cow> return type would be nicer .
  • using lazy_static seams to be the common idiom when compiling the regex

https://github.com/brson/rust-cookbook/pull/248 is a fine example of both

fn main() {
assert_eq!(
extract_login(r"I❤email@example.com"),
Some(r"I❤email".to_owned())

This comment has been minimized.

@budziq

budziq Jul 16, 2017

Collaborator

I would add some more both standard and funky testcases :)

@Ophirr33

This comment has been minimized.

Copy link
Contributor Author

Ophirr33 commented Jul 19, 2017

Addressed the comments, and I also put the example behind the lazy static examples.

@budziq
Copy link
Collaborator

budziq left a comment

Nice. I had some time to drop few comments

};
}
RE.captures(input)
.and_then(|cap| cap.get(1).map(|login| Cow::from(login.as_str())))

This comment has been minimized.

@budziq

budziq Jul 22, 2017

Collaborator

please run rustfmt on the example

lazy_static! {
static ref RE: Regex = {
let mut pattern = r"^([^@\s]+)@".to_owned();
pattern += r"([[:word:]]+\.)*[[:word:]]+$";

This comment has been minimized.

@budziq

budziq Jul 22, 2017

Collaborator

no need to construct the regex in such way please use multiline regex (whitespace insensitive) definition syntax directly within Regex::new() like in
https://brson.github.io/rust-cookbook/basics.html#run-an-external-command-and-process-stdout

any (super brief) comments would go into the regex body comments (starting with #)

use std::borrow::Cow;
// Validates that something has an @ symbol, followed by something that
// looks like a domain. Returns what came before the @ symbol, if everything

This comment has been minimized.

@budziq

budziq Jul 22, 2017

Collaborator

i would pare the comments down as much as possible or even remove them (the example should be self explanatory as much as possible.)

// Validates that something has an @ symbol, followed by something that
// looks like a domain. Returns what came before the @ symbol, if everything
// looks valid. Prevents regex recompilation using lazy_static!
fn extract_login(input: &str) -> Option<Cow<str>> {

This comment has been minimized.

@budziq

budziq Jul 22, 2017

Collaborator

is Cow necessary here?

@budziq

This comment has been minimized.

Copy link
Collaborator

budziq commented Jul 29, 2017

Hi @Ophirr33. I'm back from holidays so I should be able to give some more hands on help here. Do you need any assistance with this example?

@Ophirr33

This comment has been minimized.

Copy link
Contributor Author

Ophirr33 commented Aug 8, 2017

Deleted the comments and tried to use a named capture to make the code more self-explanatory

@budziq

This comment has been minimized.

Copy link
Collaborator

budziq commented Aug 8, 2017

thanks! merged

@budziq budziq closed this Aug 8, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.