-1

I am trying to find words that begin with a certain letter, and end with another, using variables and regex. This is the expression and input I am using, am I going wrong anywhere?

start = str(input("What should it start with?"))
end = str(input("What should it end with?"))
words = re.findall(r"\b"+ start +"\w*?"+ end +"\b", dictionary)

Dictionary is a file I open containing some words.

Chadderbox
  • 55
  • 1
  • 5

1 Answers1

1

Make sure to use r for the other string patterns:

words = re.findall(r"\b" + start + r"\w*?" + end + r"\b", dictionary)
ywbaek
  • 2,971
  • 3
  • 9
  • 28