Fikrat Ghuliev
Fikrat Ghuliev

Reputation: 1

Python3 Regular Expression problem(Data handle)

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

Answers (1)

David
David

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

Related Questions