aboutsummaryrefslogtreecommitdiff
path: root/regex/struct.Captures.html
blob: aab73fd8d39feeaf7c29acad136ce0a161417373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="rustdoc">
    <meta name="description" content="API documentation for the Rust `Captures` struct in crate `regex`.">
    <meta name="keywords" content="rust, rustlang, rust-lang, Captures">

    <title>regex::Captures - Rust</title>

    <link rel="stylesheet" type="text/css" href="../main.css">

    <link rel="shortcut icon" href="http://www.rust-lang.org/favicon.ico">
    
</head>
<body class="rustdoc">
    <!--[if lte IE 8]>
    <div class="warning">
        This old browser is unsupported and will most likely display funky
        things.
    </div>
    <![endif]-->

    

    <section class="sidebar">
        <a href='../regex/index.html'><img src='http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='' width='100'></a>
        <p class='location'><a href='index.html'>regex</a></p><script>window.sidebarCurrent = {name: 'Captures', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script>
    </section>

    <nav class="sub">
        <form class="search-form js-only">
            <div class="search-container">
                <input class="search-input" name="search"
                       autocomplete="off"
                       placeholder="Click or press 'S' to search, '?' for more options..."
                       type="search">
            </div>
        </form>
    </nav>

    <section id='main' class="content struct">
<h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>regex</a>::<wbr><a class='struct' href=''>Captures</a></span><span class='out-of-band'><span id='render-detail'>
            <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
                [<span class='inner'>&#x2212;</span>]
            </a>
        </span><a id='src-8829' class='srclink' href='../src/regex/re.rs.html#803-807' title='goto source code'>[src]</a></span></h1>
<pre class='rust struct'>pub struct Captures&lt;'t&gt; {
    // some fields omitted
}</pre><div class='docblock'><p>Captures represents a group of captured strings for a single match.</p>

<p>The 0th capture always corresponds to the entire match. Each subsequent
index corresponds to the next capture group in the regex.
If a capture group is named, then the matched string is <em>also</em> available
via the <code>name</code> method. (Note that the 0th capture is always unnamed and so
must be accessed with the <code>at</code> method.)</p>

<p>Positions returned from a capture group are always byte indices.</p>

<p><code>&#39;t</code> is the lifetime of the matched text.</p>
</div><h2 id='methods'>Methods</h2><h3 class='impl'><code>impl&lt;'t&gt; <a class='struct' href='../regex/struct.Captures.html' title='regex::Captures'>Captures</a>&lt;'t&gt;</code></h3><div class='impl-items'><h4 id='method.pos' class='method'><code>fn <a href='#method.pos' class='fnname'>pos</a>(&amp;self, i: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>) -&gt; <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a>&lt;<a href='http://doc.rust-lang.org/nightly/std/primitive.tuple.html'>(<a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>, <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>)</a>&gt;</code></h4>
<div class='docblock'><p>Returns the start and end positions of the Nth capture group.
Returns <code>None</code> if <code>i</code> is not a valid capture group or if the capture
group did not match anything.
The positions returned are <em>always</em> byte indices with respect to the
original string matched.</p>
</div><h4 id='method.at' class='method'><code>fn <a href='#method.at' class='fnname'>at</a>(&amp;self, i: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>) -&gt; <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a>&lt;&amp;'t <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>&gt;</code></h4>
<div class='docblock'><p>Returns the matched string for the capture group <code>i</code>.  If <code>i</code> isn&#39;t
a valid capture group or didn&#39;t match anything, then <code>None</code> is
returned.</p>
</div><h4 id='method.name' class='method'><code>fn <a href='#method.name' class='fnname'>name</a>(&amp;self, name: &amp;<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -&gt; <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a>&lt;&amp;'t <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>&gt;</code></h4>
<div class='docblock'><p>Returns the matched string for the capture group named <code>name</code>.  If
<code>name</code> isn&#39;t a valid capture group or didn&#39;t match anything, then
<code>None</code> is returned.</p>
</div><h4 id='method.iter' class='method'><code>fn <a href='#method.iter' class='fnname'>iter</a>(&amp;'t self) -&gt; <a class='struct' href='../regex/struct.SubCaptures.html' title='regex::SubCaptures'>SubCaptures</a>&lt;'t&gt;</code></h4>
<div class='docblock'><p>Creates an iterator of all the capture groups in order of appearance
in the regular expression.</p>
</div><h4 id='method.iter_pos' class='method'><code>fn <a href='#method.iter_pos' class='fnname'>iter_pos</a>(&amp;'t self) -&gt; <a class='struct' href='../regex/struct.SubCapturesPos.html' title='regex::SubCapturesPos'>SubCapturesPos</a>&lt;'t&gt;</code></h4>
<div class='docblock'><p>Creates an iterator of all the capture group positions in order of
appearance in the regular expression. Positions are byte indices
in terms of the original string matched.</p>
</div><h4 id='method.iter_named' class='method'><code>fn <a href='#method.iter_named' class='fnname'>iter_named</a>(&amp;'t self) -&gt; <a class='struct' href='../regex/struct.SubCapturesNamed.html' title='regex::SubCapturesNamed'>SubCapturesNamed</a>&lt;'t&gt;</code></h4>
<div class='docblock'><p>Creates an iterator of all named groups as an tuple with the group
name and the value. The iterator returns these values in arbitrary
order.</p>
</div><h4 id='method.expand' class='method'><code>fn <a href='#method.expand' class='fnname'>expand</a>(&amp;self, text: &amp;<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -&gt; <a class='struct' href='http://doc.rust-lang.org/nightly/collections/string/struct.String.html' title='collections::string::String'>String</a></code></h4>
<div class='docblock'><p>Expands all instances of <code>$name</code> in <code>text</code> to the corresponding capture
group <code>name</code>.</p>

<p><code>name</code> may be an integer corresponding to the index of the
capture group (counted by order of opening parenthesis where <code>0</code> is the
entire match) or it can be a name (consisting of letters, digits or
underscores) corresponding to a named capture group.</p>

<p>If <code>name</code> isn&#39;t a valid capture group (whether the name doesn&#39;t exist or
isn&#39;t a valid index), then it is replaced with the empty string.</p>

<p>To write a literal <code>$</code> use <code>$$</code>.</p>
</div><h4 id='method.len' class='method'><code>fn <a href='#method.len' class='fnname'>len</a>(&amp;self) -&gt; <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a></code></h4>
<div class='docblock'><p>Returns the number of captured groups.</p>
</div><h4 id='method.is_empty' class='method'><code>fn <a href='#method.is_empty' class='fnname'>is_empty</a>(&amp;self) -&gt; <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a></code></h4>
<div class='docblock'><p>Returns true if and only if there are no captured groups.</p>
</div></div></section>
    <section id='search' class="content hidden"></section>

    <section class="footer"></section>

    <div id="help" class="hidden">
        <div class="shortcuts">
            <h1>Keyboard shortcuts</h1>
            <dl>
                <dt>?</dt>
                <dd>Show this help dialog</dd>
                <dt>S</dt>
                <dd>Focus the search field</dd>
                <dt>&larrb;</dt>
                <dd>Move up in search results</dd>
                <dt>&rarrb;</dt>
                <dd>Move down in search results</dd>
                <dt>&#9166;</dt>
                <dd>Go to active search result</dd>
            </dl>
        </div>
        <div class="infos">
            <h1>Search tricks</h1>
            <p>
                Prefix searches with a type followed by a colon (e.g.
                <code>fn:</code>) to restrict the search to a given type.
            </p>
            <p>
                Accepted types are: <code>fn</code>, <code>mod</code>,
                <code>struct</code>, <code>enum</code>,
                <code>trait</code>, <code>typedef</code> (or
                <code>tdef</code>).
            </p>
            <p>
                Search functions by type signature (e.g.
                <code>vec -> usize</code>)
            </p>
        </div>
    </div>

    

    <script>
        window.rootPath = "../";
        window.currentCrate = "regex";
        window.playgroundUrl = "";
    </script>
    <script src="../jquery.js"></script>
    <script src="../main.js"></script>
    
    <script async src="../search-index.js"></script>
</body>
</html>