|
|
|
|
|
by makeworld
1728 days ago
|
|
That's because the Python regex module caches the regexes it compiles, so it only happens once. It's proper and good usage to specify the regex string inline, even in a hot path. I'd only use a variable when I'm using the same regex multiple times in code, and even then I could still just have the variable be the string. |
|
Last time I had a look the regex cache was pretty small (few hundred entries) and gets completely cleared when full. Might have improved since, but historically it was very simplistic.
I disagree that it’s “proper and good usage” to specify regex inline. It’s fine for many usages but that’s as far as I’d go.