vynabhnnqwxleicntw
vynabhnnqwxleicntw

Reputation: 17

re.search always returning NONE

I cannot seem to figure out why, regardless of what I seem to change, when I call re.search(), I always am returned NONE, as if the pattern is not present.

import re
from typing import Tuple, List
from collections import Counter
from glob import glob


def start_project(txt: str) -> Tuple[int, int]:
    
    print("before re.search")
    x = re.search("\*\*\* START OF THE PROJECT GUTENBERG EBOOK .* \*\*\*", str(str))
    print("this is the new output: ", x)


start_project("*** START OF THE PROJECT GUTENBERG EBOOK THE ILIAD ***")

Upvotes: 0

Views: 169

Answers (1)

CodeMonkey
CodeMonkey

Reputation: 23748

Need to change 2nd argument in re.search() call to the "txt" variable.

Try:

import re
from typing import Tuple, List

def start_project(txt: str) -> Tuple[int, int]:
    
    print("before re.search")
    x = re.search("\*\*\* START OF THE PROJECT GUTENBERG EBOOK .* \*\*\*", txt)
    print("this is the new output: ", x)

start_project("*** START OF THE PROJECT GUTENBERG EBOOK THE ILIAD ***")

Output:

before re.search
this is the new output:  <re.Match object; span=(0, 54), match='*** START OF THE PROJECT GUTENBERG EBOOK THE ILIA>

Upvotes: 1

Related Questions