New re feature in 3.6: local flags and example use

Ian Kelly ian.g.kelly at gmail.com
Sun Jan 1 23:45:26 EST 2017


On Sun, Jan 1, 2017 at 8:25 PM, Terry Reedy <tjreedy at udel.edu> wrote:
\> 3.6 added syntax for 'local flags'.
> '''
> (?imsx-imsx:...)
>
>     (Zero or more letters from the set 'i', 'm', 's', 'x', optionally
> followed by '-' followed by one or more letters from the same set.) The
> letters set or removes the corresponding flags: re.I (ignore case), re.M
> (multi-line), re.S (dot matches all), and re.X (verbose), for the part of
> the expression. (The flags are described in Module Contents.)
> '''
> Here is the replacement for the above, curtesy of Serhiy Storchaka.
>
> r"(?i:\br|u|f|fr|rf|b|br|rb)?"

What is the difference between the letters before the hyphen and those
after? I guess that placing the letter before means to set the flag
and after means to unset it, but it's not clear from the
documentation.



More information about the Python-list mailing list