regex - Python Regular Expressions, find Email Domain in Address -
i know i'm idiot, can't pull domain out of email address:
'blahblah@gmail.com' my desired output:
'@gmail.com' my current output:
. (it's period character)
here's code:
import re test_string = 'blahblah@gmail.com' domain = re.search('@*?\.', test_string) print domain.group() here's think regular expression says ('@*?.', test_string):
' # begin define pattern i'm looking (also tell python string) @ # find patterns beginning @ symbol ("@") * # find characters after ampersand ? # find last character before period \ # breakout (don't use next character wild card, string character) . # find "." character ' # end definition of pattern i'm looking (also tell python string) , test string # run preceding search on variable "test_string," i.e., 'blahblah@gmail.com' i'm basing off definitions here:
http://docs.activestate.com/komodo/4.4/regex-intro.html
also, searched other answers bit difficult me head around.
help appreciated, usual. thanks.
my stuff if matters:
windows 7 pro (64 bit)
python 2.6 (64 bit)
ps. stackoverflow quesiton: posts don't include new lines unless hit "return" twice in between them. example (these on different line when i'm posting):
@ - find patterns beginning @ symbol ("@") * - find characters after ampersand ? - find last character before period \ - breakout (don't use next character wild card, string character) . - find "." character , test string - run preceding search on variable "test_string," i.e., 'blahblah@gmail.com'
that's why got blank line b/w every line above. doing wrong? thx.
here's think might help
import re s = 'my name conrad, , blahblah@gmail.com email.' domain = re.search("@[\w.]+", s) print domain.group() outputs
@gmail.com how regex works:
@ - scan till see character
[\w.] set of characters potentially match, \w alphanumeric characters, , trailing period . adds set of characters.
+ 1 or more of previous set.
because regex matching period character , every alphanumeric after @, it'll match email domains in middle of sentences.
Comments
Post a Comment