8000 gh-119960: Add information about regex flags by SweetyAngel · Pull Request #119978 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
gh-119960: Add information about regex flags #119978
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2024
Merged
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
gh-119960: Add information about regex flags
  • Loading branch information
SweetyAngel committed Jun 3, 2024
commit 124b7d273fe09b9b162db36d824319b53e49beee
32 changes: 32 additions & 0 deletions Doc/library/re.rst
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,10 @@ Functions
``None`` if no position in the string matches the pattern; note that this is
different from finding a zero-length match at some point in the string.

The expression's behaviour can be modified by specifying a *flags* value.
Values can be any of the `flags`_ variables, combined using bitwise OR
(the ``|`` operator).


.. function:: match(pattern, string, flags=0)

Expand All @@ -925,13 +929,21 @@ Functions
If you want to locate a match anywhere in *string*, use :func:`search`
instead (see also :ref:`search-vs-match`).

The expression's behaviour can be modified by specifying a *flags* value.
Values can be any of the `flags`_ variables, combined using bitwise OR
(the ``|`` operator).


.. function:: fullmatch(pattern, string, flags=0)

If the whole *string* matches the regular expression *pattern*, return a
corresponding :class:`~re.Match`. Return ``None`` if the string does not match
the pattern; note that this is different from a zero-length match.

The expression's behaviour can be modified by specifying a *flags* value.
Values can be any of the `flags`_ variables, combined using bitwise OR
(the ``|`` operator).

.. versionadded:: 3.4


Expand Down Expand Up @@ -974,6 +986,10 @@ Functions
>>> re.split(r'(\W*)', '...words...')
['', '...', '', '', 'w', '', 'o', '', 'r', '', 'd', '', 's', '...', '', '', '']

The expression's behaviour can be modified by specifying a *flags* value.
Values can be any of the `flags`_ variables, combined using bitwise OR
(the ``|`` operator).

.. versionchanged:: 3.1
Added the optional flags argument.

Expand Down Expand Up @@ -1004,6 +1020,10 @@ Functions
>>> re.findall(r'(\w+)=(\d+)', 'set width=20 and height=10')
[('width', '20'), ('height', '10')]

The expression's behaviour can be modified by specifying a *flags* value.
Values can be any of the `flags`_ variables, combined using bitwise OR
(the ``|`` operator).

.. versionchanged:: 3.7
Non-empty matches can now start just after a previous empty match.

Expand All @@ -1015,6 +1035,10 @@ Functions
is scanned left-to-right, and matches are returned in the order found. Empty
matches are included in the result.

The expression's behaviour can be modified by specifying a *flags* value.
Values can be any of the `flags`_ variables, combined using bitwise OR
(the ``|`` operator).

.. versionchanged:: 3.7
Non-empty matches can now start just after a previous empty match.

Expand Down Expand Up @@ -1070,6 +1094,10 @@ Functions
character ``'0'``. The backreference ``\g<0>`` substitutes in the entire
substring matched by the RE.

The expression's behaviour can be modified by specifying a *flags* value.
Values can be any of the `flags`_ variables, combined using bitwise OR
(the ``|`` operator).

.. versionchanged:: 3.1
Added the optional flags argument.

Expand Down Expand Up @@ -1102,6 +1130,10 @@ Functions
Perform the same operation as :func:`sub`, but return a tuple ``(new_string,
number_of_subs_made)``.

The expression's behaviour can be modified by specifying a *flags* value.
Values can be any of the `flags`_ variables, combined using bitwise OR
(the ``|`` operator).


.. function:: escape(pattern)

Expand Down
Loading
0