0

Possible Duplicate:
Using a regular expression to validate an email address

I'm developing a Python application which matches any email address even if that contains at , dot and even white space between words.

Help me to develop the regex to get the expected output

Community
  • 1
  • 1
Sachith Deshan N
  • 160
  • 4
  • 14
  • I think there it doesn't talk about email addresses having (at) dot etc. – Sachith Deshan N Jan 26 '13 at 09:05
  • As if RFC-compliant addresses were not [hard enough](http://ex-parrot.com/~pdw/Mail-RFC822-Address.html), you want to add support for spam-unfriendly addresses in a validator? The whole point of spam-unfriendly addresses is to be hard to decode using a computer... – thkala Jan 26 '13 at 09:15
  • 1
    What if there are two spaces before the 'at'? How do you expect any regular expression to differentiate between, for example, 'blah blah peter at place dot edu' and 'peter jones at place dot edu'? No regex can do this because their form is identical. You would need some extremely clever machine learning to stand a chance at this. – Ant P Jan 26 '13 at 09:17
  • 1
    What about people using other conventions than `joe at example dot com`? E.g `joe -at- example -dot- com` or `joe (at) example (dot) com`... – thkala Jan 26 '13 at 09:17
  • I suspect that we have a [XY problem](http://mywiki.wooledge.org/XyProblem) case here. @SachithDeshanN: what is the *purpose* of your application? If you tell us what you are trying to do at a higher level, we might be able to help you more - as long as you are not making a mail-address harvester, that is. – thkala Jan 26 '13 at 09:19
  • Here in the username part of email. there can't be whitespaces. I mean there will be no "peter jones at place dot edu" like address I want to get only the addresses like "peterjones at place dot edu" – Sachith Deshan N Jan 26 '13 at 09:21
  • The sole purpose of the app is for a python assignment at my uni. I'm a newbie to python and this is the first assignment given for us – Sachith Deshan N Jan 26 '13 at 09:23
  • @thkala I dont want to match other conventions. I just need to match this convention since it was the requirement – Sachith Deshan N Jan 26 '13 at 09:24
  • 1
    @SachithDeshanN: agreed. The critical piece of information missing from your question was that it is a homework assignment. Homework assignments do not have to make sense :-) – thkala Jan 26 '13 at 09:38
  • but I tried and still trying to do it, I think homeworks shouldn't be posted without trying at all. Anyway thanks :) – Sachith Deshan N Jan 26 '13 at 09:41

1 Answers1

1

You could use an expression like:

[\w.+]+(?:@|\s+at\s+|\s*\(at\)\s*)(?:[\w+-]+(?:\.|\s+dot\s+))+\w+
Qtax
  • 33,241
  • 9
  • 83
  • 121