Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29745

Python Regular Expressions, find Email Domain in Address

$
0
0

I know I'm an idiot, but I can't pull the domain out of this email address:

'blahblah@gmail.com'

My desired output:

'@gmail.com'

My current output:

.

(it's just a period character)

Here's my code:

import re
test_string = 'blahblah@gmail.com'
domain = re.search('@*?\.', test_string)
print domain.group()

Here's what I think my regular expression says ('@*?.', test_string):

' # begin to define the pattern I'm looking for (also tell python this is a string)

  @ # find all patterns beginning with the at symbol ("@")

  * # find all characters after ampersand

  ? # find the last character before the period

  \ # breakout (don't use the next character as a wild card, us it is a string character)

  . # find the "." character

  ' # end definition of the pattern I'm looking for (also tell python this is a string)

  , test string # run the preceding search on the variable "test_string," i.e., 'blahblah@gmail.com'

I'm basing this off the definitions here:

http://docs.activestate.com/komodo/4.4/regex-intro.html

Also, I searched but other answers were a bit too difficult for me to get my head around.

Help is much appreciated, as usual. Thanks.

My stuff if it matters:

Windows 7 Pro (64 bit)

Python 2.6 (64 bit)


PS. StackOverflow quesiton: My posts don't include new lines unless I hit "return" twice in between them. For example (these are all on a different line when I'm posting):

@ - find all patterns beginning with the at symbol ("@") * - find all characters after ampersand ? - find the last character before the period \ - breakout (don't use the next character as a wild card, us it is a string character) . - find the "." character , test string - run the preceding search on the variable "test_string," i.e., 'blahblah@gmail.com'

That's why I got a blank line b/w every line above. What am I doing wrong? Thx.


Viewing all articles
Browse latest Browse all 29745

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>