Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 2

Question regarding Regular Expressions in Python

Solved! Go to Solution.

Hey everyone 

So I'm learning about regular expressions and I came accross an exercise which is about the email from this line :

x = "From stephen.marquard@uct.ac.za Sat Jan  5 09:14:16 2008"

I already know the solution but I was looking for the "non-greedy" answer which should give me "d@u" as the answer but I can't get it to work. Here's what I've come up with

y = re.findall('\S+?@\S+?',x)
print(y)

which results in :

['stephen.marquard@u']

Any ideas on what I have to do in order to make it work ?

Thanks !

 

 

 

1 Reply
Solution
Copilot Lvl 3
Message 2 of 2

Re: Question regarding Regular Expressions in Python

I was playing with the code and managed to get the result by 

y = re.findall('\S@\S', x)

Which gave me 

['d@u']