0

So I am using the following grep command to search over a lot of files. I want to have it pattern match against just teh validly formatted email addresses.

grep -rnw ./ -e "email here"

My question is, what syntax should I use instead of "email here" to specify the pattern for a validly formatted email? Would that be some sort of regex?

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
kaes
  • 1,267
  • 2
  • 13
  • 17
  • 1
    possible duplicate of [Using a regular expression to validate an email address](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) – ruakh Aug 03 '14 at 19:15
  • Initially I thought that this was a duplicate but now I'm not so sure, as the OP has only hinted at the use of regex rather than outright requested a regular expression. – Tom Fenech Aug 03 '14 at 19:53

1 Answers1

1

Good thinking about using regex, you can find a lot of exemples of it on the web. There is an exemple you can use for:

[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}

If you have any problem on using regex wikipedia is still a good place to learn : (check "Character classes" paragraph)

http://en.wikipedia.org/wiki/Regular_expression#Formal_language_theory

Chamlee
  • 86
  • 2
  • I encourage you to take a look at the question marked as a duplicate, perhaps then you will appreciate the complexity of using regular expressions to extract valid email addresses :) – Tom Fenech Aug 03 '14 at 19:59
  • 1
    This will fail if you have a domain like `hanson@canon.camera` since top level domain here has more than 4 characters defined. Se here for more top level example: http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains – Jotne Aug 04 '14 at 06:53