Mar-21-2020, 10:25 AM
I'm trying to find a full list of domain names from a imported text file and the correct regular expression used is this
import re hand = open('mbox-short.txt') for line in hand: line = line.rstrip() x = re.findall('[a-zA-Z0-9]\S*@(\S*[a-zA-Z0-9])', line) if len(x) > 0: print(x)However the regular expression created is way too long, so i came up with this:
x = re.findall('@\S+', line)By doing the above, i'm able to get the same exact as the longer regular expressions, however because I specify the @ in front, the results printed @ on every line too. So i'm trying to figure out if there is a way or code that I can use to hide the @ symbol in the result? Reason being it will save me the trouble of writing the longer regular expression as it's a pain in the neck.