3 回答

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超8個贊
re.compile
0|[1-9][0-9]*
0|[1-9][0-9]*
.
num = "..."# then, much later:m = re.match(num, input)
num = re.compile("...")# then, much later:m = num.match(input)

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超6個贊
$ python -m timeit -s "import re" "re.match('hello', 'hello world')"100000 loops, best of 3: 3.82 usec per loop $ python -m timeit -s "import re; h=re.compile('hello')" "h.match('hello world')"1000000 loops, best of 3: 1.26 usec per loop
re.compile
re.compile
最新情況:
% python -m timeit -s "import re" "re.match('hello', 'hello world')"1000000 loops, best of 3: 0.661 usec per loop% python -m timeit -s "import re; h=re.compile('hello')" "h.match('hello world')"1000000 loops, best of 3: 0.285 usec per loop% python -m timeit -s "import re" "h=re.compile('hello'); h.match('hello world')"1000000 loops, best of 3: 0.65 usec per loop% python --versionPython 3.6.5 :: Anaconda, Inc.
re.match(x, ...)
re.compile(x).match(...)
添加回答
舉報