-1

I need a regex to match something this:

<a space><any character/s>@<any character/s><a space>

Yes, it's a very very basic email parser.

Thanks!

  • `[.*]@[.*]` but it doesn't seem to work. I have no idea about regex :/ – Bruno Sacks Mar 20 '12 at 02:10
  • 1
    You should search around for e-mail addy regexes. There are so many about. No need to reinvent the wheel. – Jason Gennaro Mar 20 '12 at 02:13
  • There's something to be said for experimenting and learning. The e-mail address regexes out there are quite complex. – Fls'Zen Mar 20 '12 at 02:23
  • See also: http://stackoverflow.com/questions/201323/how-to-use-a-regular-expression-to-validate-an-email-addresses (and [hundreds of others](http://stackoverflow.com/search?tab=votes&q=email%20regex)) – johnsyweb Mar 20 '12 at 02:23

4 Answers4

0

Something like this? /^ [^@]+@[^ ]+ $/

Rob
  • 12,659
  • 4
  • 39
  • 56
0

The square brackets indicate a character class, which is the characters that can be present there. So, your regex would match .@. or *@*. Instead, try "\ .*@.*\ " (quotes to show the space at the end, don't include them inside your regex.

Fls'Zen
  • 4,594
  • 1
  • 29
  • 37
0

For testing e-mail, you might use the regex described here:

\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b

It still doesn't cover 100% of e-mails, but the comprehensive version is fairly involved.

rjz
  • 16,182
  • 3
  • 36
  • 35
  • The Perl one isn't 100%: it is for an obsolete RFC and also requires pre-processing to remove comments. – porges Mar 20 '12 at 02:29
  • That's true. One more log on the fire claiming that regular expressions might--just might--not be the end-all/be-all solution for testing whether or not an e-mail address is valid. – rjz Mar 20 '12 at 02:58
0
^ .+@.+ $

This translates to "the start of the string is followed by a space, one or more characters, the @ symbol, one or more characters, and the last character in the string is a space."

AerandiR
  • 5,260
  • 2
  • 20
  • 22