First off, I am new to regex and am using https://regex101.com/r/arkkVE/3 to help me learn it.
I'd like to find words from a .txt file that I have using re. So far I am able to do this, but it is very verbose and I am trying to cut back on repeated sequences of regex expressions.
currently this is what I have
Possibility = list()
with open('5LetterWords.txt') as f:
for line in f.readlines():
Possibility += re.findall(r'(?=\w)(?=.*[@#t])[\w]+(?=\w)(?=.*[@#o])[\w]+(?=\w)(?=.*[@#u])[\w]+'
, line)
print(Possibility)
This finds words that have the letters "t" and "o" and "u" in no particular order, which is the first step in what I want.
I want to add additional regex expressions that will omit words that have other characters, but I don't know how to exclude using regex.
As you can see this is starting to get really long and ugly.
Should I be using regex? Is there a better/more concise way to solve this problem?
Thanks