I have a email validation regex. what i want to achieve is, if any email does not match the regex pattern, I want to display only those characters which match with the regex and strip away which do not.
pattern=r'(^a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)'
For example: if my validation fails because there is "'" and '?' in email, then my suggested email should be with all characters except these two. If the input doesnot match the pattern then:
input="t'[email protected]"
expected output = "[email protected]"
How can I achieve this? Currently I am using,
z=list(input)
sp=[]
for j in range(len(z)):
result=re.findall(pattern,z[j])
if len(result)!=0:
sp.append(result[0])
output=''.join(sp)
However, this is giving me a blank output. Apart from this, another problem with this approach is, it will not detect an anomally, if the email input has 2'@'
Can anyone suggest what will be the correct way of proceeding here?