⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contents_of_module_re.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>4.2.3 Module Contents</title>
<META NAME="description" CONTENT="4.2.3 Module Contents">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="re-objects.html" tppabs="http://www.python.org/doc/current/lib/re-objects.html">
<LINK REL="previous" href="matching-searching.html" tppabs="http://www.python.org/doc/current/lib/matching-searching.html">
<LINK REL="up" href="module-re.html" tppabs="http://www.python.org/doc/current/lib/module-re.html">
<LINK REL="next" href="re-objects.html" tppabs="http://www.python.org/doc/current/lib/re-objects.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="matching-searching.html" tppabs="http://www.python.org/doc/current/lib/matching-searching.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="module-re.html" tppabs="http://www.python.org/doc/current/lib/module-re.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="re-objects.html" tppabs="http://www.python.org/doc/current/lib/re-objects.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="matching-searching.html" tppabs="http://www.python.org/doc/current/lib/matching-searching.html">4.2.2 Matching vs. Searching</A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-re.html" tppabs="http://www.python.org/doc/current/lib/module-re.html">4.2 re  </A>
<b class="navlabel">Next:</b> <a class="sectref" href="re-objects.html" tppabs="http://www.python.org/doc/current/lib/re-objects.html">4.2.4 Regular Expression Objects</A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION006230000000000000000">
4.2.3 Module Contents</A>
</H2>

<P>
The module defines the following functions and constants, and an exception:

<P>
<dl><dt><b><a name='l2h-590'><tt class='function'>compile</tt></a></b> (<var>pattern</var><big>[</big><var>, flags</var><big>]</big>)
<dd>
  Compile a regular expression pattern into a regular expression
  object, which can be used for matching using its <tt class="function">match()</tt> and
  <tt class="function">search()</tt> methods, described below.  

<P>
The expression's behaviour can be modified by specifying a
  <var>flags</var> value.  Values can be any of the following variables,
  combined using bitwise OR (the <code>|</code> operator).

<P>
The sequence

<P>
<dl><dd><pre class="verbatim">
prog = re.compile(pat)
result = prog.match(str)
</pre></dl>

<P>
is equivalent to

<P>
<dl><dd><pre class="verbatim">
result = re.match(pat, str)
</pre></dl>

<P>
but the version using <tt class="function">compile()</tt> is more efficient when the
expression will be used several times in a single program.
</dl>

<P>
<dl><dt><b><a name='l2h-591'><tt>I</tt></a></b>
<dd>
<dt><b><a name='l2h-605'><tt>IGNORECASE</tt></a></b><dd>
Perform case-insensitive matching; expressions like <tt class="regexp">[A-Z]</tt> will match
lowercase letters, too.  This is not affected by the current locale.
</dl>

<P>
<dl><dt><b><a name='l2h-592'><tt>L</tt></a></b>
<dd>
<dt><b><a name='l2h-606'><tt>LOCALE</tt></a></b><dd>
Make <tt class="regexp">&#92;w</tt>, <tt class="regexp">&#92;W</tt>, <tt class="regexp">&#92;b</tt>, and
<tt class="regexp">&#92;B</tt> dependent on the current locale. 
</dl>

<P>
<dl><dt><b><a name='l2h-593'><tt>M</tt></a></b>
<dd>
<dt><b><a name='l2h-607'><tt>MULTILINE</tt></a></b><dd>
When specified, the pattern character "<tt class="character">^</tt>" matches at the
beginning of the string and at the beginning of each line
(immediately following each newline); and the pattern character
"<tt class="character">$</tt>" matches at the end of the string and at the end of each line
(immediately preceding each newline).
By default, "<tt class="character">^</tt>" matches only at the beginning of the string, and
"<tt class="character">$</tt>" only at the end of the string and immediately before the
newline (if any) at the end of the string. 
</dl>

<P>
<dl><dt><b><a name='l2h-594'><tt>S</tt></a></b>
<dd>
<dt><b><a name='l2h-608'><tt>DOTALL</tt></a></b><dd>
Make the "<tt class="character">.</tt>" special character match any character at all,
including a newline; without this flag, "<tt class="character">.</tt>" will match
anything <i>except</i> a newline.
</dl>

<P>
<dl><dt><b><a name='l2h-595'><tt>U</tt></a></b>
<dd>
<dt><b><a name='l2h-609'><tt>UNICODE</tt></a></b><dd>
Make <tt class="regexp">&#92;w</tt>, <tt class="regexp">&#92;W</tt>, <tt class="regexp">&#92;b</tt>, and
<tt class="regexp">&#92;B</tt> dependent on the Unicode character properties database.

New in version 2.0.

</dl>

<P>
<dl><dt><b><a name='l2h-596'><tt>X</tt></a></b>
<dd>
<dt><b><a name='l2h-610'><tt>VERBOSE</tt></a></b><dd>
This flag allows you to write regular expressions that look nicer.
Whitespace within the pattern is ignored, 
except when in a character class or preceded by an unescaped
backslash, and, when a line contains a "<tt class="character">#</tt>" neither in a character
class or preceded by an unescaped backslash, all characters from the
leftmost such "<tt class="character">#</tt>" through the end of the line are ignored.
</dl>

<P>
<dl><dt><b><a name='l2h-597'><tt class='function'>search</tt></a></b> (<var>pattern, string</var><big>[</big><var>, flags</var><big>]</big>)
<dd>
  Scan through <var>string</var> looking for a location where the regular
  expression <var>pattern</var> produces a match, and return a
  corresponding <tt class="class">MatchObject</tt> instance.
  Return <code>None</code> 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.
</dl>

<P>
<dl><dt><b><a name='l2h-598'><tt class='function'>match</tt></a></b> (<var>pattern, string</var><big>[</big><var>, flags</var><big>]</big>)
<dd>
  If zero or more characters at the beginning of <var>string</var> match

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -