summaryrefslogtreecommitdiff
path: root/pypers/nre.html
diff options
context:
space:
mode:
authormichele.simionato <devnull@localhost>2007-12-02 11:13:11 +0000
committermichele.simionato <devnull@localhost>2007-12-02 11:13:11 +0000
commit20ce686b0193d67ea56823a30551140f88b3aee1 (patch)
tree76015e7e4dc0b000bd857a2bdba6fb7976ac29a7 /pypers/nre.html
parentf08f40335ad7f0ac961f25dabaaed34c4d4bcc44 (diff)
downloadmicheles-20ce686b0193d67ea56823a30551140f88b3aee1.tar.gz
Commited all py papers into Google code
Diffstat (limited to 'pypers/nre.html')
-rwxr-xr-xpypers/nre.html123
1 files changed, 123 insertions, 0 deletions
diff --git a/pypers/nre.html b/pypers/nre.html
new file mode 100755
index 0000000..035e8ff
--- /dev/null
+++ b/pypers/nre.html
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="generator" content="Docutils 0.2.9: http://docutils.sourceforge.net/" />
+<title>Module nre</title>
+<link rel="stylesheet" href="default.css" type="text/css" />
+</head>
+<body>
+<div class="document" id="module-nre">
+<h1 class="title">Module <tt class="literal"><span class="pre">nre</span></tt></h1>
+<p>nre - new style regular expressions</p>
+<p>The <tt class="literal"><span class="pre">nre</span></tt> module adopt an object-oriented approach to regular expressions.
+It provides only a class, <tt class="literal"><span class="pre">Regexp</span></tt>, which instances are regular expression
+objects, or reobj for short. It can be imported with</p>
+<blockquote>
+<pre class="doctest-block">
+&gt;&gt;&gt; from nre import Regexp
+</pre>
+</blockquote>
+<p>(notice that <tt class="literal"><span class="pre">from</span> <span class="pre">nre</span> <span class="pre">import</span> <span class="pre">*</span></tt> would have the same effect).</p>
+<div class="section" id="classes">
+<h1><a name="classes">Classes</a></h1>
+<p><tt class="literal"><span class="pre">class</span> <span class="pre">Regexp(object):</span></tt></p>
+<blockquote>
+<p>The class of regular expression objects. Instantiated with the signature</p>
+<p>reobj=Regexp(pattern,name=None,doc=None,isgroup=False)</p>
+<p>pattern is a (raw) string which can be associated with a valid
+regular expression; it the pattern contains an sequence ' #',
+only the chars on the left of ' #' are retained, whereas all
+the chars on the right of ' #' are assumed to be a comment.
+If you want to avoid this interpretation, you must escape #.
+Then the comment is stripped with the pattern and assigned with
+the docstring, unless an explicit docstring was already provided.
+if name is not None, associates a name to the reobj;
+if doc is not None, associates a docstring to the reobj;
+if isgroup is True, converts the regexp in a named group
+<tt class="literal"><span class="pre">(?P&lt;name&gt;regexp)</span></tt> or an numbered group <tt class="literal"><span class="pre">(regexp)</span></tt> if
+name is None.</p>
+<p>re-objects are callable. For instance</p>
+<pre class="doctest-block">
+&gt;&gt;&gt; a=Regexp('x # named group')('a')
+</pre>
+<p>returns a named group regular expression, whereas</p>
+<pre class="doctest-block">
+&gt;&gt;&gt; b=Regexp('x # numbered group')
+</pre>
+<p>returns a numbered group regexp.</p>
+<pre class="doctest-block">
+&gt;&gt;&gt; print a
+&gt;&gt;&gt; print b
+</pre>
+<p><tt class="literal"><span class="pre">compose(self,other,oper):</span></tt></p>
+<blockquote>
+Compose regular expression objects with strings or with themselves.
+<tt class="literal"><span class="pre">oper</span></tt> is one of the strings &quot;__add__&quot;, &quot;__radd__&quot;, &quot;__or__&quot;,
+&quot;__ror__&quot;.</blockquote>
+<p><tt class="literal"><span class="pre">__ror__(self,other):</span></tt></p>
+<blockquote>
+<p>Combines a regular expression object to a string
+or another reobj using <tt class="literal"><span class="pre">|</span></tt> . Works from the right. Example:</p>
+<pre class="doctest-block">
+&gt;&gt;&gt; print 'x' | Regexp('y')
+&lt;reobj '&lt;noname&gt;':x|y&gt;
+</pre>
+</blockquote>
+<p><tt class="literal"><span class="pre">__radd__(self,other):</span></tt></p>
+<blockquote>
+<p>Adds a regular expression object to a string or another
+reobj. Works from the right. Example:</p>
+<pre class="doctest-block">
+&gt;&gt;&gt; print 'x' + Regexp('y')
+&lt;reobj '&lt;noname&gt;':xy&gt;
+</pre>
+</blockquote>
+<p><tt class="literal"><span class="pre">__or__(self,other):</span></tt></p>
+<blockquote>
+<p>Combines a regular expression object to a string
+or to another reobj using <tt class="literal"><span class="pre">|</span></tt> . Works from the left. Example:</p>
+<pre class="doctest-block">
+&gt;&gt;&gt; print Regexp('x') | 'y'
+&lt;reobj '&lt;noname&gt;':x|y&gt;
+</pre>
+<p>Works well with named reobj too:</p>
+<pre class="doctest-block">
+&gt;&gt;&gt; a=Regexp('x',name='a')
+&gt;&gt;&gt; b=Regexp('y',name='b')
+&gt;&gt;&gt; print a|b
+&lt;reobj 'a__b':x|y&gt;
+</pre>
+</blockquote>
+<p><tt class="literal"><span class="pre">__add__(self,other):</span></tt></p>
+<blockquote>
+<p>Adds a regular expression object to a string or
+to another reobj. Works from the left. Example:</p>
+<pre class="doctest-block">
+&gt;&gt;&gt; print Regexp('x') + 'y'
+&lt;reobj '&lt;noname&gt;':xy&gt;
+</pre>
+<p>Works well with named reobj too:</p>
+<pre class="doctest-block">
+&gt;&gt;&gt; a=Regexp('x',name='a')
+&gt;&gt;&gt; b=Regexp('y',name='b')
+&gt;&gt;&gt; print a+b
+&lt;reobj 'a_b':xy&gt;
+</pre>
+</blockquote>
+<p><tt class="literal"><span class="pre">__call__(self,name=None):</span></tt></p>
+<blockquote>
+Returns a grouped regular expression object. The group is named
+if the regexp was already named or if an explicit name is passed.</blockquote>
+</blockquote>
+</div>
+</div>
+<hr class="footer"/>
+<div class="footer">
+<a class="reference" href="nre.rst">View document source</a>.
+Generated on: 2003-09-23 10:57 UTC.
+Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
+</div>
+</body>
+</html>