I am compiling a regex pattern to use it multiple times. 

However, I want to use it inside a function, so for now I use it as a global variable. However, I don't need it outside of this specific function, so I wonder if I can write it as a static variable, meaning it would be compiled once and for all function instances/occurrences.

```
import re
p = re.compile(“[0-9|-]+”)

def search(txt):
    global p

    # some stuff
    return p.search(txt).group(0)

```

PS of course, in this specific example, It won't save me any sufficient​ amount of memory, I just want to find if I can do this in general. Also, it would me more readable that way, I think.​