I have some emails
[email protected]
[email protected]
[email protected]
I need to ignore strings that contain info, sales, so I used pattern:
'/(?!spb)[a-zA-Z0-9-_\.]+@[a-z0-9\.]+$'
But it returns []. What am I doing wrong?
I have some emails
[email protected]
[email protected]
[email protected]
I need to ignore strings that contain info, sales, so I used pattern:
'/(?!spb)[a-zA-Z0-9-_\.]+@[a-z0-9\.]+$'
But it returns []. What am I doing wrong?
Perhaps more understandable and maintainable:
import re
string = """
[email protected]
[email protected]
[email protected]
some other text here with emails [email protected] included"""
rx = re.compile(r'\S+@\S+')
def ignore(value):
lst = ['info', 'sales']
for i in lst:
if i in value:
return False
return True
emails = filter(ignore, rx.findall(string))
print(emails)
# ['[email protected]', '[email protected]']
Simply adjust the lst of ignore() as needed.
https://regex101.com/r/505NB9/1 It looks like the first two chars are not needed.
if 'info' in email.split('@')[0] or 'sales' in email.split('@')[0]:See my working example below.
^to indicate the start of a line as well.[] is probably because you didn't use the re.MULTILINE option. The re.MULTILINE flag tells python to make the ‘^’ and ‘$’ special characters match the start or end of any line within a string, as opposed to the start or end of the entire string.import re
test = '[email protected]\[email protected]\[email protected]'
print(test)
[email protected]
[email protected]
[email protected]
pattern = re.compile('^(?!info|sales)[[a-zA-Z0-9-_.]+@[a-z0-9.]+$', re.MULTILINE)
emails = re.findall(pattern, test)
print(emails)
['[email protected]']
emails = re.findall(pattern, test)re.findall(r'(?m)^(?!.*(?:info|sales))\S+@\S+\.\S+$', s)