Re: re.IGNORECASE and re.VERBOSE
Simon Brunning wrote: > On 7/18/05, Jeremy <[EMAIL PROTECTED]> wrote: >> I am using regular expressions and I would like to use both >> re.IGNORECASE and re.VERBOSE options. I want to do something like the >> following (which doesn't work): >> >> matsearch = r'''^\ {0,4}([mM]\d+) ''' >> MatSearch = re.compile(matsearch, re.VERBOSE, re.IGNORECASE) > > MatSearch = re.compile(matsearch, re.IGNORECASE + re.VERBOSE) While this works when you are only combining flags, the general way of handling flags (= bit-fields) is with the three bit-wise operators '^', '&' and '|'. Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: re.IGNORECASE and re.VERBOSE
Jeremy wrote: > I am using regular expressions and I would like to use both > re.IGNORECASE and re.VERBOSE options. I want to do something like the > following (which doesn't work): > > matsearch = r'''^\ {0,4}([mM]\d+) ''' > MatSearch = re.compile(matsearch, re.VERBOSE, re.IGNORECASE) > > Does anyone have any suggestions? These flags are combined using the bit-wise OR operator. re.compile(matsearch, re.VERBOSE|re.IGNORECASE) Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: re.IGNORECASE and re.VERBOSE
On 7/18/05, Jeremy <[EMAIL PROTECTED]> wrote: > I am using regular expressions and I would like to use both > re.IGNORECASE and re.VERBOSE options. I want to do something like the > following (which doesn't work): > > matsearch = r'''^\ {0,4}([mM]\d+) ''' > MatSearch = re.compile(matsearch, re.VERBOSE, re.IGNORECASE) MatSearch = re.compile(matsearch, re.IGNORECASE + re.VERBOSE) -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: re.IGNORECASE and re.VERBOSE
On 7/18/05, Jeremy <[EMAIL PROTECTED]> wrote: > I am using regular expressions and I would like to use both > re.IGNORECASE and re.VERBOSE options. I want to do something like the > following (which doesn't work): > > matsearch = r'''^\ {0,4}([mM]\d+) ''' > MatSearch = re.compile(matsearch, re.VERBOSE, re.IGNORECASE) You need to OR them together: re.compile(matsearch, re.VERBOSE | re.IGNORECASE) -- http://mail.python.org/mailman/listinfo/python-list
re.IGNORECASE and re.VERBOSE
I am using regular expressions and I would like to use both re.IGNORECASE and re.VERBOSE options. I want to do something like the following (which doesn't work): matsearch = r'''^\ {0,4}([mM]\d+) ''' MatSearch = re.compile(matsearch, re.VERBOSE, re.IGNORECASE) Does anyone have any suggestions? Thanks, Jeremy -- http://mail.python.org/mailman/listinfo/python-list