Question: In a python script I am using re.finditer for finding strings inside a text file.

How do I know if re.finditer does not find a specific string?

I tried with

```
for n in re.finditer("string",line2):
    if n.start() == "":
        print("empty")

```

But this does not work. 

(I would like to use re.finditer as it is already in the script)

newest python

Answer: 
If the regex pattern is not matched anywhere in the text you're searching, `finditer` will return an empty iterable. That is, your `for` loop will never run the code in the indented block.

There are a few ways you could detect this. One might be to set an initial value for the `n` loop variable and then test if it has been updated by the loop code:

```
n = None

for n in re.finditer(pattern, text):
    ... # do stuff with found matches here

if n is None:    # n was never assigned to by the loop code
    ... # do stuff for no match situation here

```
With those requirements, you could do something like:

```
n = re.finditer(pattern, line2)
try:
    first_item = next(n)
    #do something with the rest of the iterable eg:
    print(first_item)
    for item in n:
        print(n)
except StopIteration:
    print("empty")

```