I understand I am a fool, however i can't pull the domain using this current email address:
My preferred output:
My current output:
(it is simply a period of time character)
Here's my code:
import re test_string = 'firstname.lastname@example.org' domain = re.search('@*?.', test_string) print domain.group()
Some tips about what I believe my regular expression states ('@*?.', test_string):
' # start to define the pattern I am searching for (also tell python this can be a string) @ # find all designs starting with the at symbol ("@") * # find all figures after ampersand ? # discover the last character prior to the period # breakout (avoid using the following character like a wild card, us it's a string character) . # discover the "." character ' # finish meaning of the pattern I am searching for (also tell python this can be a string) , test string # run the preceding explore the variable "test_string," i.e., 'email@example.com'
I am basing this from the definitions here:
Also, I looked but other solutions were a little too hard that i can get my mind around.
Assistance is much appreciated, as always. Thanks.
My stuff whether it matters:
Home windows 7 Professional (64 bit)
Python 2.6 (64 bit)
PS. StackOverflow quesiton: My posts don't include new lines unless of course I hit "return" two times between them. For instance (they are all on the different line when I am posting):
@ - find all designs starting with the at symbol ("@") * - find all figures after ampersand ? - discover the last character prior to the period - breakout (avoid using the following character like a wild card, us it's a string character) . - discover the "." character , test string - run the preceding explore the variable "test_string," i.e., 'firstname.lastname@example.org'
This is exactly why I acquired an empty line b/w every line above. What am I doing wrong? Thx.
Here's something I believe may help
import re s = 'My title is Conrad, and email@example.com is my email.' domain = re.search("@[w.]+", s) print domain.group()
The way the regex works:
@ - scan until you check this out character
[w.] some figures to potentially match, so
w is alphanumeric figures, and also the trailing period
. contributes to that group of figures.
+ a number of from the previous set.
As this regex is matching the time character and each alphanumeric after an
@, it'll match email domain names even in the center of sentences.
Ok, so why wouldn't you use split? (or partition )
Or use other string techniques like find
>>> s="firstname.lastname@example.org" >>> s[ s.find("@") : ] '@gmail.com' >>>
and when you will extract out emails from another text
f=open("file") for line in f: words= line.split() if "@" in words: print "@"+words.split("@")[-1] f.close()
Using regular expressions:
>>> re.search('@.*', test_string).group() '@gmail.com'
An alternative way:
>>> '@' + test_string.split('@') '@gmail.com'