[Solved] is it correct? i hope someone can help me hehe [closed]


your code seems to lack the actual regular expression that will find the result you are looking for. If I understand correctly, your aim is to find lines starting with F, followed by ANY two characters. If this is the case, you wish to print the line to the terminal. Let me guide you:

import re

file_hand = open("mbox-short.txt")

for line in file_hand:  #NB: After a new scope is entered, use indentation

    result = re.search("$f..", line)   #pattern, search string

    #$ matches character before the first in a line
    #. matches 1 occurence of any character

    if result.group() != "":  #access result of re.search with group() method
        print(line)

I trust you can follow this. If you need capital F, I will leave it as a homework exercise for you to find out how to do the capital F.

You can practice with regexp here:
https://regexr.com/

Or read more about it here:
https://www.youtube.com/watch?v=rhzKDrUiJVk

0

solved is it correct? i hope someone can help me hehe [closed]