Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Doc/library/re.rst
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,11 @@ form.
programs that use only a few regular expressions at a time needn't worry
about compiling regular expressions.

.. class:: RegexFlag

An :class:`enum.IntFlag` class containing the regex options listed below.

.. versionadded:: 3.11 - added to ``__all__``

.. data:: A
ASCII
Expand Down Expand Up @@ -710,6 +715,17 @@ form.
string and immediately before the newline (if any) at the end of the string.
Corresponds to the inline flag ``(?m)``.

.. data:: NOFLAG

Indicates no flag being applied, the value is ``0``. This flag may be used
as a default value for a function keyword argument or as a base value that
will be conditionally ORed with other flags. Example of use as a default
value::

def myfunc(text, flag=re.NOFLAG):
return re.match(text, flag)

.. versionadded:: 3.11

.. data:: S
DOTALL
Expand Down
3 changes: 2 additions & 1 deletion Lib/re.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,15 @@
"findall", "finditer", "compile", "purge", "template", "escape",
"error", "Pattern", "Match", "A", "I", "L", "M", "S", "X", "U",
"ASCII", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
"UNICODE",
"UNICODE", "NOFLAG", "RegexFlag",
]

__version__ = "2.2.1"

@enum.global_enum
@enum._simple_enum(enum.IntFlag, boundary=enum.KEEP)
class RegexFlag:
NOFLAG = 0
ASCII = A = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
IGNORECASE = I = sre_compile.SRE_FLAG_IGNORECASE # ignore case
LOCALE = L = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add :class:`~re.RegexFlag` to ``re.__all__`` and documented it. Add
:data:`~re.RegexFlag.NOFLAG` to indicate no flags being set.