Reputation: 1
i have a question for regex library
import re
data = input("type ", )
with open('data.txt', 'r', encoding="utf-8") as f:
lines = f.readlines()
for line in lines:
if re.match(data, line):
print (line)
break
data.txt content
HELLO - hi im robot
HI - hello im robot
ADD - pls add
My question is. When user type "hello","hi" how can i print data in data.txt? because first words start a big.
Upvotes: 0
Views: 34
Reputation: 3046
You could add re.IGNORECASE:
if re.match(data, line, re.IGNORECASE):
In that way, the regex would not be case sensitive anymore.
Upvotes: 1