python 2.3 regex problem
how do i set the regular expressions flags like multiline and ignorecase in python 2.3?
in python 2.6 its like thi开发者_如何学运维s
re.findall(pattern,string, re.multiline | re.ignorecase)
but this doesn't seem to wok for python 2.3, any ideas?
pointers appreciated
edit: sorry, it was python 2.3 not 2.4
Compile the regexp in advance with re.compile(pattern[, flags])
. Then you can pass the options as the second parameter.
the flags are uppercase in 2.4, e.g.:
re.findall(pattern,string, re.MULTILINE | re.IGNORECASE)
works for me;
Python 2.4.3 (#1, Sep 3 2009, 15:37:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.findall("Test","Test\ntest\nTEST",re.MULTILINE|re.IGNORECASE)
['Test', 'test', 'TEST']
精彩评论