G
G
Guerro692020-05-19 20:54:21
Python
Guerro69, 2020-05-19 20:54:21

Python, regular expressions, why is this happening?

I have one code that looks for numbers from a file.

match = re.findall(r"\№[0-9]{6,}", f.read())
match1 = re.findall(r"\№[0-9]{6,}", f.read())
print(str(len(match)))
print(str(len(match1)))

The two variables are exactly the same, but why does match show 355, and match1 0, why is that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2020-05-19
@Guerro69

so try:

txt = f.read()
match = re.findall(r"\№[0-9]{6,}", txt)
match1 = re.findall(r"\№[0-9]{6,}", txt)

print(str(len(match)))
print(str(len(match1)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question