A flag is just an int. From the re doc, you can see there is a ignorecase flag:
"
I
IGNORECASE
Perform case-insensitive matching; expressions like [A-Z] will match lowercase letters, too. This is not affected by the current locale.
"
Using the ignorecase flag:
>>> import re >>> print re.I 2 >>> print re.IGNORECASE 2 >>> r = re.compile("hello", re.IGNORECASE) >>> print r.pattern 'hello' >>> match = r.search("heLLo") >>> match.group() 'heLLo'
As the doc says, you can combine several flags with the '|' operator: r = re.compile("your_regexp", re.SOMEFLAG|re.SOMEOTHERFLAG)
Xah Lee wrote:
Python re module has methods flags and pattern. How to use these exactly?
e.g. i tried
print patternObj.flags()
and the error is some "int object is not callable".
newpattern=re.compile(ur'\w+',patternObj.flags())
also bad.
similar error for patternObj.pattern(). (and i suppose the same for groupindex() )
thanks.
Xah [EMAIL PROTECTED] â http://xahlee.org/
-- http://mail.python.org/mailman/listinfo/python-list