Why use re.Compile? What’s the difference between using only the desired Pattern?

Asked

Viewed 25 times

1

We can find some difference when using re.Compile inside Python?

Assuming a file with 10 lines composed by dates and a file with 10,000 lines of dates. A Pattern could be pattern = re.compile(r'\d{2}\/\d{2}\/\d{4}')
and the second only the match
re.match('\d{2}\/\d{2}\/\d{4}', 'variavel_para_arquivo')

  • Perhaps because of re.compile return an object, you can reuse it in to check other strings.

  • About re.compile, the duplicate suggested above already explains well. About using regex for dates, I suggest a read here: https://answall.com/q/3660/112052

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.