Why does my search for a certain RegEx pattern using python parser return a greedy result with non-greedy '+?' operator?

27 Views Asked by At

I used a non-greedy(lazy) +? operator but it is being greedy

I expect the RE \S+?@\S+ when matched against the string 'From [email protected] Sat Jan 5 09:14:16 2008' to match '[email protected]', but it matched '[email protected]'. Below is the Python code I used.

import re
string = 'From [email protected] Sat Jan  5 09:14:16 2008'
out = re.findall('\S+?@\S+', string)
print(out)

When I tried the same string and pattern in Notepad++, I got the same result.

0

There are 0 best solutions below