0

how do i set the regular expressions flags like multiline and ignorecase in python 2.3?

in python 2.6 its like this

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

1
  • re.multiline doesn't work on 2.6 or any other version-- there's no such attribute. The names of those flags (like all module-level constants) are in UPPERCASE in all Python versions. When asking a question, show the code that you actually ran, and don't type it from memory, use copy/paste. Commented Nov 30, 2009 at 11:31

2 Answers 2

1

Compile the regexp in advance with re.compile(pattern[, flags]). Then you can pass the options as the second parameter.

Sign up to request clarification or add additional context in comments.

Comments

1

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']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.