ignore case only for a part of the regex?
vlastimil.brom at gmail.com
Sun Dec 30 17:38:31 CET 2012
2012/12/30 Helmut Jarausch <jarausch at skynet.be>:
> is there a means to specify that 'ignore-case' should only apply to a part
> of a regex?
> the regex should match Msg-id:, Msg-Id, ... but not msg-id: and so on.
> I've tried the pattern
> but (?i) makes the whole pattern ignoring case.
> In my simple case I could say
> but that's a bit clumsy.
> Is there a more elegant way? Is there a way to compose a pattern
> from subpatterns which are compiled with different flags?
> Many thanks for a hint,
you may check the new regex implementation for python
which allows (among many other improvements) for scoped flags:
>>> import regex
>>> regex.findall(r"Msg-(?i:id):", "the regex should match Msg-id:, Msg-Id:, ... but not msg-id:, MSG-ID: and so on")
More information about the Python-list