Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
791468f7
Commit
791468f7
authored
Apr 03, 1998
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some clarifications of out-of-range group indexes/names
parent
a50547e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
10 deletions
+20
-10
Doc/lib/libre.tex
Doc/lib/libre.tex
+10
-5
Doc/libre.tex
Doc/libre.tex
+10
-5
No files found.
Doc/lib/libre.tex
View file @
791468f7
...
...
@@ -420,7 +420,7 @@ previous match, so \samp{sub('x*', '-', 'abc')} returns \code{'-a-b-c-'}.
If
\var
{
repl
}
is a string, any backslash escapes in it are processed.
That is,
\samp
{
\e
n
}
is converted to a single newline character,
\samp
{
\e
r
}
is converted to a linefeed, and so forth. Unknown escapes
such as
\samp
{
\e
j
}
are
XXX
. Backreferences, such as
\samp
{
\e
6
}
are
such as
\samp
{
\e
j
}
are
left alone
. Backreferences, such as
\samp
{
\e
6
}
are
replaced with the substring matched by group 6 in the pattern.
In addition to character escapes and backreferences as described
...
...
@@ -521,13 +521,18 @@ Without arguments, \var{group1} defaults to zero (i.e. the whole match
is returned).
If a
\var
{
groupN
}
argument is zero, the corresponding return value is the
entire matching string; if it is in the inclusive range [1..99], it is
the string matching the the corresponding parenthesized group. If no
such group exists, the corresponding result is
\code
{
None
}
.
the string matching the the corresponding parenthesized group. If a
group number is negative or larger than the number of groups defined
in the pattern, an
\exception
{
IndexError
}
exception is raised.
If a group is contained in a part of the pattern that did not match,
the corresponding result is
\code
{
None
}
. If a group is contained in a
part of the pattern that matched multiple times, the last match is
returned.
If the regular expression uses the
\code
{
(?P<
\var
{
name
}
>...)
}
syntax,
the
\var
{
groupN
}
arguments may also be strings identifying groups by
their group name.
their group name. If a string argument is not used as a group name in
the pattern, an
\exception
{
IndexError
}
exception is raised.
A moderately complicated example:
...
...
Doc/libre.tex
View file @
791468f7
...
...
@@ -420,7 +420,7 @@ previous match, so \samp{sub('x*', '-', 'abc')} returns \code{'-a-b-c-'}.
If
\var
{
repl
}
is a string, any backslash escapes in it are processed.
That is,
\samp
{
\e
n
}
is converted to a single newline character,
\samp
{
\e
r
}
is converted to a linefeed, and so forth. Unknown escapes
such as
\samp
{
\e
j
}
are
XXX
. Backreferences, such as
\samp
{
\e
6
}
are
such as
\samp
{
\e
j
}
are
left alone
. Backreferences, such as
\samp
{
\e
6
}
are
replaced with the substring matched by group 6 in the pattern.
In addition to character escapes and backreferences as described
...
...
@@ -521,13 +521,18 @@ Without arguments, \var{group1} defaults to zero (i.e. the whole match
is returned).
If a
\var
{
groupN
}
argument is zero, the corresponding return value is the
entire matching string; if it is in the inclusive range [1..99], it is
the string matching the the corresponding parenthesized group. If no
such group exists, the corresponding result is
\code
{
None
}
.
the string matching the the corresponding parenthesized group. If a
group number is negative or larger than the number of groups defined
in the pattern, an
\exception
{
IndexError
}
exception is raised.
If a group is contained in a part of the pattern that did not match,
the corresponding result is
\code
{
None
}
. If a group is contained in a
part of the pattern that matched multiple times, the last match is
returned.
If the regular expression uses the
\code
{
(?P<
\var
{
name
}
>...)
}
syntax,
the
\var
{
groupN
}
arguments may also be strings identifying groups by
their group name.
their group name. If a string argument is not used as a group name in
the pattern, an
\exception
{
IndexError
}
exception is raised.
A moderately complicated example:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment