Just to add to Seppo's answer. According to http://docs.python.org/2.6/library/re.html, there is still a way to pass flags directly to 'sub' in 2.6 which might be useful if you have to make a 2.7 code with a lot of sub's compatible with 2.6. To quote the manual:
... if you need to specify regular expression flags, you must use a RE object, or use embedded modifiers in a pattern; for example, sub("(?i)b+", "x", "bbbb BBBB") returns 'x x'
and
(?iLmsux) (One or more letters from the set 'i', 'L', 'm', 's', 'u', 'x'.) The group matches the empty string; the letters set the corresponding flags: re.I (ignore case), re.L (locale dependent), re.M (multi-line), re.S (dot matches all), re.U (Unicode dependent), and re.X (verbose), for the entire regular expression. (The flags are described in Module Contents.) This is useful if you wish to include the flags as part of the regular expression, instead of passing a flag argument to the re.compile() function.
In practice, this means
print re.sub("class", "function", "Class object", flags=re.I)
can be rewritten using modifiers (?ms) as
print re.sub("(?i)class", "function", "Class object")