| <!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="A compiled regular expression for matching Unicode strings."><meta name="keywords" content="rust, rustlang, rust-lang, Regex"><title>Regex in regex - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../regex/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../regex/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Regex</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.as_str">as_str</a></li><li><a href="#method.capture_locations">capture_locations</a></li><li><a href="#method.capture_names">capture_names</a></li><li><a href="#method.captures">captures</a></li><li><a href="#method.captures_at">captures_at</a></li><li><a href="#method.captures_iter">captures_iter</a></li><li><a href="#method.captures_len">captures_len</a></li><li><a href="#method.captures_read">captures_read</a></li><li><a href="#method.captures_read_at">captures_read_at</a></li><li><a href="#method.find">find</a></li><li><a href="#method.find_at">find_at</a></li><li><a href="#method.find_iter">find_iter</a></li><li><a href="#method.is_match">is_match</a></li><li><a href="#method.is_match_at">is_match_at</a></li><li><a href="#method.new">new</a></li><li><a href="#method.replace">replace</a></li><li><a href="#method.replace_all">replace_all</a></li><li><a href="#method.replacen">replacen</a></li><li><a href="#method.shortest_match">shortest_match</a></li><li><a href="#method.shortest_match_at">shortest_match_at</a></li><li><a href="#method.split">split</a></li><li><a href="#method.splitn">splitn</a></li><li><a href="#method.static_captures_len">static_captures_len</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-Clone-for-Regex">Clone</a></li><li><a href="#impl-Debug-for-Regex">Debug</a></li><li><a href="#impl-Display-for-Regex">Display</a></li><li><a href="#impl-FromStr-for-Regex">FromStr</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-Regex">RefUnwindSafe</a></li><li><a href="#impl-Send-for-Regex">Send</a></li><li><a href="#impl-Sync-for-Regex">Sync</a></li><li><a href="#impl-Unpin-for-Regex">Unpin</a></li><li><a href="#impl-UnwindSafe-for-Regex">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-Regex">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-Regex">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-Regex">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-Regex">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-Regex">Into<U></a></li><li><a href="#impl-ToOwned-for-Regex">ToOwned</a></li><li><a href="#impl-ToString-for-Regex">ToString</a></li><li><a href="#impl-TryFrom%3CU%3E-for-Regex">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-Regex">TryInto<U></a></li></ul></section><h2><a href="index.html">In regex</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Struct <a href="index.html">regex</a>::<wbr><a class="struct" href="#">Regex</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/regex/re_unicode.rs.html#158">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="item-decl"><pre class="rust struct"><code>pub struct Regex(_);</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A compiled regular expression for matching Unicode strings.</p> |
| <p>It is represented as either a sequence of bytecode instructions (dynamic) |
| or as a specialized Rust function (native). It can be used to search, split |
| or replace text. All searching is done with an implicit <code>.*?</code> at the |
| beginning and end of an expression. To force an expression to match the |
| whole string (or a prefix or a suffix), you must use an anchor like <code>^</code> or |
| <code>$</code> (or <code>\A</code> and <code>\z</code>).</p> |
| <p>While this crate will handle Unicode strings (whether in the regular |
| expression or in the search text), all positions returned are <strong>byte |
| indices</strong>. Every byte index is guaranteed to be at a Unicode code point |
| boundary.</p> |
| <p>The lifetimes <code>'r</code> and <code>'t</code> in this crate correspond to the lifetime of a |
| compiled regular expression and text to search, respectively.</p> |
| <p>The only methods that allocate new strings are the string replacement |
| methods. All other methods (searching and splitting) return borrowed |
| pointers into the string given.</p> |
| <h2 id="examples"><a href="#examples">Examples</a></h2> |
| <p>Find the location of a US phone number:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>re = Regex::new(<span class="string">"[0-9]{3}-[0-9]{3}-[0-9]{4}"</span>).unwrap(); |
| <span class="kw">let </span>mat = re.find(<span class="string">"phone: 111-222-3333"</span>).unwrap(); |
| <span class="macro">assert_eq!</span>((mat.start(), mat.end()), (<span class="number">7</span>, <span class="number">19</span>));</code></pre></div> |
| <h2 id="using-the-stdstrpattern-methods-with-regex"><a href="#using-the-stdstrpattern-methods-with-regex">Using the <code>std::str::pattern</code> methods with <code>Regex</code></a></h2> |
| <blockquote> |
| <p><strong>Note</strong>: This section requires that this crate is compiled with the |
| <code>pattern</code> Cargo feature enabled, which <strong>requires nightly Rust</strong>.</p> |
| </blockquote> |
| <p>Since <code>Regex</code> implements <code>Pattern</code>, you can use regexes with methods |
| defined on <code>&str</code>. For example, <code>is_match</code>, <code>find</code>, <code>find_iter</code> |
| and <code>split</code> can be replaced with <code>str::contains</code>, <code>str::find</code>, |
| <code>str::match_indices</code> and <code>str::split</code>.</p> |
| <p>Here are some examples:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">let </span>re = Regex::new(<span class="string">r"\d+"</span>).unwrap(); |
| <span class="kw">let </span>haystack = <span class="string">"a111b222c"</span>; |
| |
| <span class="macro">assert!</span>(haystack.contains(<span class="kw-2">&</span>re)); |
| <span class="macro">assert_eq!</span>(haystack.find(<span class="kw-2">&</span>re), <span class="prelude-val">Some</span>(<span class="number">1</span>)); |
| <span class="macro">assert_eq!</span>(haystack.match_indices(<span class="kw-2">&</span>re).collect::<Vec<<span class="kw">_</span>>>(), |
| <span class="macro">vec!</span>[(<span class="number">1</span>, <span class="string">"111"</span>), (<span class="number">5</span>, <span class="string">"222"</span>)]); |
| <span class="macro">assert_eq!</span>(haystack.split(<span class="kw-2">&</span>re).collect::<Vec<<span class="kw">_</span>>>(), <span class="macro">vec!</span>[<span class="string">"a"</span>, <span class="string">"b"</span>, <span class="string">"c"</span>]);</code></pre></div> |
| </div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><div id="implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Regex" class="impl has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#191-606">source</a><a href="#impl-Regex" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h3></section></summary><div class="docblock"><p>Core regular expression methods.</p> |
| </div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.new" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#196-198">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a>(re: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a>, <a class="enum" href="enum.Error.html" title="enum regex::Error">Error</a>></h4></section></summary><div class="docblock"><p>Compiles a regular expression. Once compiled, it can be used repeatedly |
| to search, split or replace text in a string.</p> |
| <p>If an invalid expression is given, then an error is returned.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_match" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#219-221">source</a><h4 class="code-header">pub fn <a href="#method.is_match" class="fnname">is_match</a>(&self, text: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns true if and only if there is a match for the regex in the |
| string given.</p> |
| <p>It is recommended to use this method if all you need to do is test |
| a match, since the underlying matching engine may be able to do less |
| work.</p> |
| <h5 id="example"><a href="#example">Example</a></h5> |
| <p>Test if some text contains at least one word with exactly 13 |
| Unicode word characters:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>text = <span class="string">"I categorically deny having triskaidekaphobia."</span>; |
| <span class="macro">assert!</span>(Regex::new(<span class="string">r"\b\w{13}\b"</span>).unwrap().is_match(text));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.find" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#244-246">source</a><h4 class="code-header">pub fn <a href="#method.find" class="fnname">find</a><'t>(&self, text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="struct.Match.html" title="struct regex::Match">Match</a><'t>></h4></section></summary><div class="docblock"><p>Returns the start and end byte range of the leftmost-first match in |
| <code>text</code>. If no match exists, then <code>None</code> is returned.</p> |
| <p>Note that this should only be used if you want to discover the position |
| of the match. Testing the existence of a match is faster if you use |
| <code>is_match</code>.</p> |
| <h5 id="example-1"><a href="#example-1">Example</a></h5> |
| <p>Find the start and end location of the first word with exactly 13 |
| Unicode word characters:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>text = <span class="string">"I categorically deny having triskaidekaphobia."</span>; |
| <span class="kw">let </span>mat = Regex::new(<span class="string">r"\b\w{13}\b"</span>).unwrap().find(text).unwrap(); |
| <span class="macro">assert_eq!</span>(mat.start(), <span class="number">2</span>); |
| <span class="macro">assert_eq!</span>(mat.end(), <span class="number">15</span>);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.find_iter" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#266-268">source</a><h4 class="code-header">pub fn <a href="#method.find_iter" class="fnname">find_iter</a><'r, 't>(&'r self, text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="struct" href="struct.Matches.html" title="struct regex::Matches">Matches</a><'r, 't><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.Matches.html" title="struct regex::Matches">Matches</a><'r, 't></span><code class="content"><span class="where fmt-newline">impl<'r, 't> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="struct.Matches.html" title="struct regex::Matches">Matches</a><'r, 't></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="associatedtype">Item</a> = <a class="struct" href="struct.Match.html" title="struct regex::Match">Match</a><'t>;</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>Returns an iterator for each successive non-overlapping match in |
| <code>text</code>, returning the start and end byte indices with respect to |
| <code>text</code>.</p> |
| <h5 id="example-2"><a href="#example-2">Example</a></h5> |
| <p>Find the start and end location of every word with exactly 13 Unicode |
| word characters:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>text = <span class="string">"Retroactively relinquishing remunerations is reprehensible."</span>; |
| <span class="kw">for </span>mat <span class="kw">in </span>Regex::new(<span class="string">r"\b\w{13}\b"</span>).unwrap().find_iter(text) { |
| <span class="macro">println!</span>(<span class="string">"{:?}"</span>, mat); |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.captures" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#333-335">source</a><h4 class="code-header">pub fn <a href="#method.captures" class="fnname">captures</a><'t>(&self, text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="struct.Captures.html" title="struct regex::Captures">Captures</a><'t>></h4></section></summary><div class="docblock"><p>Returns the capture groups corresponding to the leftmost-first |
| match in <code>text</code>. Capture group <code>0</code> always corresponds to the entire |
| match. If no match is found, then <code>None</code> is returned.</p> |
| <p>You should only use <code>captures</code> if you need access to the location of |
| capturing group matches. Otherwise, <code>find</code> is faster for discovering |
| the location of the overall match.</p> |
| <h5 id="examples-1"><a href="#examples-1">Examples</a></h5> |
| <p>Say you have some text with movie names and their release years, |
| like “‘Citizen Kane’ (1941)”. It’d be nice if we could search for text |
| looking like that, while also extracting the movie name and its release |
| year separately.</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>re = Regex::new(<span class="string">r"'([^']+)'\s+\((\d{4})\)"</span>).unwrap(); |
| <span class="kw">let </span>text = <span class="string">"Not my favorite movie: 'Citizen Kane' (1941)."</span>; |
| <span class="kw">let </span>caps = re.captures(text).unwrap(); |
| <span class="macro">assert_eq!</span>(caps.get(<span class="number">1</span>).unwrap().as_str(), <span class="string">"Citizen Kane"</span>); |
| <span class="macro">assert_eq!</span>(caps.get(<span class="number">2</span>).unwrap().as_str(), <span class="string">"1941"</span>); |
| <span class="macro">assert_eq!</span>(caps.get(<span class="number">0</span>).unwrap().as_str(), <span class="string">"'Citizen Kane' (1941)"</span>); |
| <span class="comment">// You can also access the groups by index using the Index notation. |
| // Note that this will panic on an invalid index. |
| </span><span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="number">1</span>], <span class="string">"Citizen Kane"</span>); |
| <span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="number">2</span>], <span class="string">"1941"</span>); |
| <span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="number">0</span>], <span class="string">"'Citizen Kane' (1941)"</span>);</code></pre></div> |
| <p>Note that the full match is at capture group <code>0</code>. Each subsequent |
| capture group is indexed by the order of its opening <code>(</code>.</p> |
| <p>We can make this example a bit clearer by using <em>named</em> capture groups:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>re = Regex::new(<span class="string">r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)"</span>) |
| .unwrap(); |
| <span class="kw">let </span>text = <span class="string">"Not my favorite movie: 'Citizen Kane' (1941)."</span>; |
| <span class="kw">let </span>caps = re.captures(text).unwrap(); |
| <span class="macro">assert_eq!</span>(caps.name(<span class="string">"title"</span>).unwrap().as_str(), <span class="string">"Citizen Kane"</span>); |
| <span class="macro">assert_eq!</span>(caps.name(<span class="string">"year"</span>).unwrap().as_str(), <span class="string">"1941"</span>); |
| <span class="macro">assert_eq!</span>(caps.get(<span class="number">0</span>).unwrap().as_str(), <span class="string">"'Citizen Kane' (1941)"</span>); |
| <span class="comment">// You can also access the groups by name using the Index notation. |
| // Note that this will panic on an invalid group name. |
| </span><span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="string">"title"</span>], <span class="string">"Citizen Kane"</span>); |
| <span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="string">"year"</span>], <span class="string">"1941"</span>); |
| <span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="number">0</span>], <span class="string">"'Citizen Kane' (1941)"</span>); |
| </code></pre></div> |
| <p>Here we name the capture groups, which we can access with the <code>name</code> |
| method or the <code>Index</code> notation with a <code>&str</code>. Note that the named |
| capture groups are still accessible with <code>get</code> or the <code>Index</code> notation |
| with a <code>usize</code>.</p> |
| <p>The <code>0</code>th capture group is always unnamed, so it must always be |
| accessed with <code>get(0)</code> or <code>[0]</code>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.captures_iter" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#362-367">source</a><h4 class="code-header">pub fn <a href="#method.captures_iter" class="fnname">captures_iter</a><'r, 't>(&'r self, text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="struct" href="struct.CaptureMatches.html" title="struct regex::CaptureMatches">CaptureMatches</a><'r, 't><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.CaptureMatches.html" title="struct regex::CaptureMatches">CaptureMatches</a><'r, 't></span><code class="content"><span class="where fmt-newline">impl<'r, 't> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="struct.CaptureMatches.html" title="struct regex::CaptureMatches">CaptureMatches</a><'r, 't></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="associatedtype">Item</a> = <a class="struct" href="struct.Captures.html" title="struct regex::Captures">Captures</a><'t>;</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>Returns an iterator over all the non-overlapping capture groups matched |
| in <code>text</code>. This is operationally the same as <code>find_iter</code>, except it |
| yields information about capturing group matches.</p> |
| <h5 id="example-3"><a href="#example-3">Example</a></h5> |
| <p>We can use this to find all movie titles and their release years in |
| some text, where the movie is formatted like “‘Title’ (xxxx)”:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>re = Regex::new(<span class="string">r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)"</span>) |
| .unwrap(); |
| <span class="kw">let </span>text = <span class="string">"'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."</span>; |
| <span class="kw">for </span>caps <span class="kw">in </span>re.captures_iter(text) { |
| <span class="macro">println!</span>(<span class="string">"Movie: {:?}, Released: {:?}"</span>, |
| <span class="kw-2">&</span>caps[<span class="string">"title"</span>], <span class="kw-2">&</span>caps[<span class="string">"year"</span>]); |
| } |
| <span class="comment">// Output: |
| // Movie: Citizen Kane, Released: 1941 |
| // Movie: The Wizard of Oz, Released: 1939 |
| // Movie: M, Released: 1931</span></code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#387-389">source</a><h4 class="code-header">pub fn <a href="#method.split" class="fnname">split</a><'r, 't>(&'r self, text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="struct" href="struct.Split.html" title="struct regex::Split">Split</a><'r, 't><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.Split.html" title="struct regex::Split">Split</a><'r, 't></span><code class="content"><span class="where fmt-newline">impl<'r, 't> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="struct.Split.html" title="struct regex::Split">Split</a><'r, 't></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="associatedtype">Item</a> = &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>;</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>Returns an iterator of substrings of <code>text</code> delimited by a match of the |
| regular expression. Namely, each element of the iterator corresponds to |
| text that <em>isn’t</em> matched by the regular expression.</p> |
| <p>This method will <em>not</em> copy the text given.</p> |
| <h5 id="example-4"><a href="#example-4">Example</a></h5> |
| <p>To split a string delimited by arbitrary amounts of spaces or tabs:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>re = Regex::new(<span class="string">r"[ \t]+"</span>).unwrap(); |
| <span class="kw">let </span>fields: Vec<<span class="kw-2">&</span>str> = re.split(<span class="string">"a b \t c\td e"</span>).collect(); |
| <span class="macro">assert_eq!</span>(fields, <span class="macro">vec!</span>[<span class="string">"a"</span>, <span class="string">"b"</span>, <span class="string">"c"</span>, <span class="string">"d"</span>, <span class="string">"e"</span>]);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.splitn" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#411-417">source</a><h4 class="code-header">pub fn <a href="#method.splitn" class="fnname">splitn</a><'r, 't>(&'r self, text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, limit: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="struct" href="struct.SplitN.html" title="struct regex::SplitN">SplitN</a><'r, 't><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.SplitN.html" title="struct regex::SplitN">SplitN</a><'r, 't></span><code class="content"><span class="where fmt-newline">impl<'r, 't> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="struct.SplitN.html" title="struct regex::SplitN">SplitN</a><'r, 't></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="associatedtype">Item</a> = &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>;</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>Returns an iterator of at most <code>limit</code> substrings of <code>text</code> delimited |
| by a match of the regular expression. (A <code>limit</code> of <code>0</code> will return no |
| substrings.) Namely, each element of the iterator corresponds to text |
| that <em>isn’t</em> matched by the regular expression. The remainder of the |
| string that is not split will be the last element in the iterator.</p> |
| <p>This method will <em>not</em> copy the text given.</p> |
| <h5 id="example-5"><a href="#example-5">Example</a></h5> |
| <p>Get the first two words in some text:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>re = Regex::new(<span class="string">r"\W+"</span>).unwrap(); |
| <span class="kw">let </span>fields: Vec<<span class="kw-2">&</span>str> = re.splitn(<span class="string">"Hey! How are you?"</span>, <span class="number">3</span>).collect(); |
| <span class="macro">assert_eq!</span>(fields, <span class="macro">vec!</span>(<span class="string">"Hey"</span>, <span class="string">"How"</span>, <span class="string">"are you?"</span>));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.replace" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#523-529">source</a><h4 class="code-header">pub fn <a href="#method.replace" class="fnname">replace</a><'t, R: <a class="trait" href="trait.Replacer.html" title="trait regex::Replacer">Replacer</a>>(&self, text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, rep: R) -> <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'t, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>></h4></section></summary><div class="docblock"><p>Replaces the leftmost-first match with the replacement provided. |
| The replacement can be a regular string (where <code>$N</code> and <code>$name</code> are |
| expanded to match capture groups) or a function that takes the matches’ |
| <code>Captures</code> and returns the replaced string.</p> |
| <p>If no match is found, then a copy of the string is returned unchanged.</p> |
| <h5 id="replacement-string-syntax"><a href="#replacement-string-syntax">Replacement string syntax</a></h5> |
| <p>All instances of <code>$name</code> in the replacement text is replaced with 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’t a valid capture group (whether the name doesn’t exist |
| or isn’t a valid index), then it is replaced with the empty string.</p> |
| <p>The longest possible name is used. e.g., <code>$1a</code> looks up the capture |
| group named <code>1a</code> and not the capture group at index <code>1</code>. To exert more |
| precise control over the name, use braces, e.g., <code>${1}a</code>.</p> |
| <p>To write a literal <code>$</code> use <code>$$</code>.</p> |
| <h5 id="examples-2"><a href="#examples-2">Examples</a></h5> |
| <p>Note that this function is polymorphic with respect to the replacement. |
| In typical usage, this can just be a normal string:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>re = Regex::new(<span class="string">"[^01]+"</span>).unwrap(); |
| <span class="macro">assert_eq!</span>(re.replace(<span class="string">"1078910"</span>, <span class="string">""</span>), <span class="string">"1010"</span>);</code></pre></div> |
| <p>But anything satisfying the <code>Replacer</code> trait will work. For example, |
| a closure of type <code>|&Captures| -> String</code> provides direct access to the |
| captures corresponding to a match. This allows one to access |
| capturing group matches easily:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>re = Regex::new(<span class="string">r"([^,\s]+),\s+(\S+)"</span>).unwrap(); |
| <span class="kw">let </span>result = re.replace(<span class="string">"Springsteen, Bruce"</span>, |caps: <span class="kw-2">&</span>Captures| { |
| <span class="macro">format!</span>(<span class="string">"{} {}"</span>, <span class="kw-2">&</span>caps[<span class="number">2</span>], <span class="kw-2">&</span>caps[<span class="number">1</span>]) |
| }); |
| <span class="macro">assert_eq!</span>(result, <span class="string">"Bruce Springsteen"</span>);</code></pre></div> |
| <p>But this is a bit cumbersome to use all the time. Instead, a simple |
| syntax is supported that expands <code>$name</code> into the corresponding capture |
| group. Here’s the last example, but using this expansion technique |
| with named capture groups:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>re = Regex::new(<span class="string">r"(?P<last>[^,\s]+),\s+(?P<first>\S+)"</span>).unwrap(); |
| <span class="kw">let </span>result = re.replace(<span class="string">"Springsteen, Bruce"</span>, <span class="string">"$first $last"</span>); |
| <span class="macro">assert_eq!</span>(result, <span class="string">"Bruce Springsteen"</span>);</code></pre></div> |
| <p>Note that using <code>$2</code> instead of <code>$first</code> or <code>$1</code> instead of <code>$last</code> |
| would produce the same result. To write a literal <code>$</code> use <code>$$</code>.</p> |
| <p>Sometimes the replacement string requires use of curly braces to |
| delineate a capture group replacement and surrounding literal text. |
| For example, if we wanted to join two words together with an |
| underscore:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>re = Regex::new(<span class="string">r"(?P<first>\w+)\s+(?P<second>\w+)"</span>).unwrap(); |
| <span class="kw">let </span>result = re.replace(<span class="string">"deep fried"</span>, <span class="string">"${first}_$second"</span>); |
| <span class="macro">assert_eq!</span>(result, <span class="string">"deep_fried"</span>);</code></pre></div> |
| <p>Without the curly braces, the capture group name <code>first_</code> would be |
| used, and since it doesn’t exist, it would be replaced with the empty |
| string.</p> |
| <p>Finally, sometimes you just want to replace a literal string with no |
| regard for capturing group expansion. This can be done by wrapping a |
| byte string with <code>NoExpand</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::NoExpand; |
| |
| <span class="kw">let </span>re = Regex::new(<span class="string">r"(?P<last>[^,\s]+),\s+(\S+)"</span>).unwrap(); |
| <span class="kw">let </span>result = re.replace(<span class="string">"Springsteen, Bruce"</span>, NoExpand(<span class="string">"$2 $last"</span>)); |
| <span class="macro">assert_eq!</span>(result, <span class="string">"$2 $last"</span>);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.replace_all" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#537-543">source</a><h4 class="code-header">pub fn <a href="#method.replace_all" class="fnname">replace_all</a><'t, R: <a class="trait" href="trait.Replacer.html" title="trait regex::Replacer">Replacer</a>>(&self, text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, rep: R) -> <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'t, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>></h4></section></summary><div class="docblock"><p>Replaces all non-overlapping matches in <code>text</code> with the replacement |
| provided. This is the same as calling <code>replacen</code> with <code>limit</code> set to |
| <code>0</code>.</p> |
| <p>See the documentation for <code>replace</code> for details on how to access |
| capturing group matches in the replacement string.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.replacen" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#551-605">source</a><h4 class="code-header">pub fn <a href="#method.replacen" class="fnname">replacen</a><'t, R: <a class="trait" href="trait.Replacer.html" title="trait regex::Replacer">Replacer</a>>(<br> &self,<br> text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>,<br> limit: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>,<br> rep: R<br>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a><'t, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>></h4></section></summary><div class="docblock"><p>Replaces at most <code>limit</code> non-overlapping matches in <code>text</code> with the |
| replacement provided. If <code>limit</code> is 0, then all non-overlapping matches |
| are replaced.</p> |
| <p>See the documentation for <code>replace</code> for details on how to access |
| capturing group matches in the replacement string.</p> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Regex-1" class="impl has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#609-752">source</a><a href="#impl-Regex-1" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h3></section></summary><div class="docblock"><p>Advanced or “lower level” search methods.</p> |
| </div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.shortest_match" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#638-640">source</a><h4 class="code-header">pub fn <a href="#method.shortest_match" class="fnname">shortest_match</a>(&self, text: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>></h4></section></summary><div class="docblock"><p>Returns the end location of a match in the text given.</p> |
| <p>This method may have the same performance characteristics as |
| <code>is_match</code>, except it provides an end location for a match. In |
| particular, the location returned <em>may be shorter</em> than the proper end |
| of the leftmost-first match that you would find via <code>Regex::find</code>.</p> |
| <p>Note that it is not guaranteed that this routine finds the shortest or |
| “earliest” possible match. Instead, the main idea of this API is that |
| it returns the offset at the point at which the internal regex engine |
| has determined that a match has occurred. This may vary depending on |
| which internal regex engine is used, and thus, the offset itself may |
| change.</p> |
| <h5 id="example-6"><a href="#example-6">Example</a></h5> |
| <p>Typically, <code>a+</code> would match the entire first sequence of <code>a</code> in some |
| text, but <code>shortest_match</code> can give up as soon as it sees the first |
| <code>a</code>.</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>text = <span class="string">"aaaaa"</span>; |
| <span class="kw">let </span>pos = Regex::new(<span class="string">r"a+"</span>).unwrap().shortest_match(text); |
| <span class="macro">assert_eq!</span>(pos, <span class="prelude-val">Some</span>(<span class="number">1</span>));</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.shortest_match_at" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#648-654">source</a><h4 class="code-header">pub fn <a href="#method.shortest_match_at" class="fnname">shortest_match_at</a>(&self, text: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, start: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>></h4></section></summary><div class="docblock"><p>Returns the same as <code>shortest_match</code>, but starts the search at the |
| given offset.</p> |
| <p>The significance of the starting point is that it takes the surrounding |
| context into consideration. For example, the <code>\A</code> anchor can only match |
| when <code>start == 0</code>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_match_at" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#662-664">source</a><h4 class="code-header">pub fn <a href="#method.is_match_at" class="fnname">is_match_at</a>(&self, text: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, start: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns the same as is_match, but starts the search at the given |
| offset.</p> |
| <p>The significance of the starting point is that it takes the surrounding |
| context into consideration. For example, the <code>\A</code> anchor can only |
| match when <code>start == 0</code>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.find_at" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#672-681">source</a><h4 class="code-header">pub fn <a href="#method.find_at" class="fnname">find_at</a><'t>(&self, text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, start: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="struct.Match.html" title="struct regex::Match">Match</a><'t>></h4></section></summary><div class="docblock"><p>Returns the same as find, but starts the search at the given |
| offset.</p> |
| <p>The significance of the starting point is that it takes the surrounding |
| context into consideration. For example, the <code>\A</code> anchor can only |
| match when <code>start == 0</code>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.captures_at" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#689-700">source</a><h4 class="code-header">pub fn <a href="#method.captures_at" class="fnname">captures_at</a><'t>(&self, text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, start: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="struct.Captures.html" title="struct regex::Captures">Captures</a><'t>></h4></section></summary><div class="docblock"><p>Returns the same as <a href="struct.Regex.html#method.captures" title="Regex::captures"><code>Regex::captures</code></a>, but starts the search at the |
| given offset.</p> |
| <p>The significance of the starting point is that it takes the surrounding |
| context into consideration. For example, the <code>\A</code> anchor can only |
| match when <code>start == 0</code>.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.captures_read" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#712-718">source</a><h4 class="code-header">pub fn <a href="#method.captures_read" class="fnname">captures_read</a><'t>(<br> &self,<br> locs: &mut <a class="struct" href="struct.CaptureLocations.html" title="struct regex::CaptureLocations">CaptureLocations</a>,<br> text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a><br>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="struct.Match.html" title="struct regex::Match">Match</a><'t>></h4></section></summary><div class="docblock"><p>This is like <code>captures</code>, but uses |
| <a href="struct.CaptureLocations.html"><code>CaptureLocations</code></a> |
| instead of |
| <a href="struct.Captures.html"><code>Captures</code></a> in order to amortize allocations.</p> |
| <p>To create a <code>CaptureLocations</code> value, use the |
| <code>Regex::capture_locations</code> method.</p> |
| <p>This returns the overall match if this was successful, which is always |
| equivalence to the <code>0</code>th capture group.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.captures_read_at" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#726-736">source</a><h4 class="code-header">pub fn <a href="#method.captures_read_at" class="fnname">captures_read_at</a><'t>(<br> &self,<br> locs: &mut <a class="struct" href="struct.CaptureLocations.html" title="struct regex::CaptureLocations">CaptureLocations</a>,<br> text: &'t <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>,<br> start: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a><br>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="struct.Match.html" title="struct regex::Match">Match</a><'t>></h4></section></summary><div class="docblock"><p>Returns the same as captures, but starts the search at the given |
| offset and populates the capture locations given.</p> |
| <p>The significance of the starting point is that it takes the surrounding |
| context into consideration. For example, the <code>\A</code> anchor can only |
| match when <code>start == 0</code>.</p> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Regex-2" class="impl has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#755-825">source</a><a href="#impl-Regex-2" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h3></section></summary><div class="docblock"><p>Auxiliary methods.</p> |
| </div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_str" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#757-759">source</a><h4 class="code-header">pub fn <a href="#method.as_str" class="fnname">as_str</a>(&self) -> &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a></h4></section></summary><div class="docblock"><p>Returns the original string of this regex.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.capture_names" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#762-764">source</a><h4 class="code-header">pub fn <a href="#method.capture_names" class="fnname">capture_names</a>(&self) -> <a class="struct" href="struct.CaptureNames.html" title="struct regex::CaptureNames">CaptureNames</a><'_><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.CaptureNames.html" title="struct regex::CaptureNames">CaptureNames</a><'r></span><code class="content"><span class="where fmt-newline">impl<'r> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="struct.CaptureNames.html" title="struct regex::CaptureNames">CaptureNames</a><'r></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="associatedtype">Item</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&'r <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>>;</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>Returns an iterator over the capture names.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.captures_len" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#767-769">source</a><h4 class="code-header">pub fn <a href="#method.captures_len" class="fnname">captures_len</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the number of captures.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.static_captures_len" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#807-809">source</a><h4 class="code-header">pub fn <a href="#method.static_captures_len" class="fnname">static_captures_len</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>></h4></section></summary><div class="docblock"><p>Returns the total number of capturing groups that appear in every |
| possible match.</p> |
| <p>If the number of capture groups can vary depending on the match, then |
| this returns <code>None</code>. That is, a value is only returned when the number |
| of matching groups is invariant or “static.”</p> |
| <p>Note that like <a href="struct.Regex.html#method.captures_len" title="Regex::captures_len"><code>Regex::captures_len</code></a>, this <strong>does</strong> include the |
| implicit capturing group corresponding to the entire match. Therefore, |
| when a non-None value is returned, it is guaranteed to be at least <code>1</code>. |
| Stated differently, a return value of <code>Some(0)</code> is impossible.</p> |
| <h5 id="example-7"><a href="#example-7">Example</a></h5> |
| <p>This shows a few cases where a static number of capture groups is |
| available and a few cases where it is not.</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>regex::Regex; |
| |
| <span class="kw">let </span>len = |pattern| { |
| Regex::new(pattern).map(|re| re.static_captures_len()) |
| }; |
| |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">1</span>), len(<span class="string">"a"</span>)<span class="question-mark">?</span>); |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">2</span>), len(<span class="string">"(a)"</span>)<span class="question-mark">?</span>); |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">2</span>), len(<span class="string">"(a)|(b)"</span>)<span class="question-mark">?</span>); |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">3</span>), len(<span class="string">"(a)(b)|(c)(d)"</span>)<span class="question-mark">?</span>); |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, len(<span class="string">"(a)|b"</span>)<span class="question-mark">?</span>); |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, len(<span class="string">"a|(b)"</span>)<span class="question-mark">?</span>); |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, len(<span class="string">"(b)*"</span>)<span class="question-mark">?</span>); |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">2</span>), len(<span class="string">"(b)+"</span>)<span class="question-mark">?</span>); |
| </code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.capture_locations" class="method has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#813-815">source</a><h4 class="code-header">pub fn <a href="#method.capture_locations" class="fnname">capture_locations</a>(&self) -> <a class="struct" href="struct.CaptureLocations.html" title="struct regex::CaptureLocations">CaptureLocations</a></h4></section></summary><div class="docblock"><p>Returns an empty set of capture locations that can be reused in |
| multiple calls to <code>captures_read</code> or <code>captures_read_at</code>.</p> |
| </div></details></div></details></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Clone-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#157">source</a><a href="#impl-Clone-for-Regex" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#157">source</a><a href="#method.clone" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone" class="fnname">clone</a>(&self) -> <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h4></section></summary><div class='docblock'>Returns a copy of the value. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone_from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/clone.rs.html#132-134">source</a></span><a href="#method.clone_from" class="anchor"></a><h4 class="code-header">const fn <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from" class="fnname">clone_from</a>(&mut self, source: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>Self)</h4></section></summary><div class='docblock'>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#167-172">source</a><a href="#impl-Debug-for-Regex" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt-1" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#169-171">source</a><a href="#method.fmt-1" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class="docblock"><p>Shows the original regular expression.</p> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Display-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#160-165">source</a><a href="#impl-Display-for-Regex" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> for <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#162-164">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#tymethod.fmt" class="fnname">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class="docblock"><p>Shows the original regular expression.</p> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-FromStr-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#181-188">source</a><a href="#impl-FromStr-for-Regex" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/str/traits/trait.FromStr.html" title="trait core::str::traits::FromStr">FromStr</a> for <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_str" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/regex/re_unicode.rs.html#185-187">source</a><a href="#method.from_str" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/str/traits/trait.FromStr.html#tymethod.from_str" class="fnname">from_str</a>(s: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a>, <a class="enum" href="enum.Error.html" title="enum regex::Error">Error</a>></h4></section></summary><div class="docblock"><p>Attempts to parse a string into a regular expression</p> |
| </div></details><details class="rustdoc-toggle" open><summary><section id="associatedtype.Err" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Err" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/str/traits/trait.FromStr.html#associatedtype.Err" class="associatedtype">Err</a> = <a class="enum" href="enum.Error.html" title="enum regex::Error">Error</a></h4></section></summary><div class='docblock'>The associated error which can be returned from parsing.</div></details></div></details></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe-for-Regex" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-Regex" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h3></section><section id="impl-Send-for-Regex" class="impl has-srclink"><a href="#impl-Send-for-Regex" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h3></section><section id="impl-Sync-for-Regex" class="impl has-srclink"><a href="#impl-Sync-for-Regex" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h3></section><section id="impl-Unpin-for-Regex" class="impl has-srclink"><a href="#impl-Unpin-for-Regex" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h3></section><section id="impl-UnwindSafe-for-Regex" class="impl has-srclink"><a href="#impl-UnwindSafe-for-Regex" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.Regex.html" title="struct regex::Regex">Regex</a></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#200">source</a><a href="#impl-Any-for-Regex" class="anchor"></a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<span class="where fmt-newline">where<br> T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#201">source</a><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#211">source</a><a href="#impl-Borrow%3CT%3E-for-Regex" class="anchor"></a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#213">source</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#220">source</a><a href="#impl-BorrowMut%3CT%3E-for-Regex" class="anchor"></a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#221">source</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#733">source</a><a href="#impl-From%3CT%3E-for-Regex" class="anchor"></a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#736">source</a></span><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#717">source</a><a href="#impl-Into%3CU%3E-for-Regex" class="anchor"></a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T<span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#725">source</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html#tymethod.into" class="fnname">into</a>(self) -> U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p> |
| <p>That is, this conversion is whatever the implementation of |
| <code><a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="From">From</a><T> for U</code> chooses to do.</p> |
| </div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-ToOwned-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#83">source</a><a href="#impl-ToOwned-for-Regex" class="anchor"></a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html" title="trait alloc::borrow::ToOwned">ToOwned</a> for T<span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Owned" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Owned" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#associatedtype.Owned" class="associatedtype">Owned</a> = T</h4></section></summary><div class='docblock'>The resulting type after obtaining ownership.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_owned" class="method trait-impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#88">source</a><a href="#method.to_owned" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#tymethod.to_owned" class="fnname">to_owned</a>(&self) -> T</h4></section></summary><div class='docblock'>Creates owned data from borrowed data, usually by cloning. <a href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone_into" class="method trait-impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#92">source</a><a href="#method.clone_into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#method.clone_into" class="fnname">clone_into</a>(&self, target: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T)</h4></section></summary><div class='docblock'>Uses borrowed data to replace owned data, usually by cloning. <a href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-ToString-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/alloc/string.rs.html#2497">source</a><a href="#impl-ToString-for-Regex" class="anchor"></a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/string/trait.ToString.html" title="trait alloc::string::ToString">ToString</a> for T<span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_string" class="method trait-impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/alloc/string.rs.html#2503">source</a><a href="#method.to_string" class="anchor"></a><h4 class="code-header">default fn <a href="https://doc.rust-lang.org/nightly/alloc/string/trait.ToString.html#tymethod.to_string" class="fnname">to_string</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section></summary><div class='docblock'>Converts the given value to a <code>String</code>. <a href="https://doc.rust-lang.org/nightly/alloc/string/trait.ToString.html#tymethod.to_string">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#775">source</a><a href="#impl-TryFrom%3CU%3E-for-Regex" class="anchor"></a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T<span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#781">source</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from" class="fnname">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-Regex" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#760">source</a><a href="#impl-TryInto%3CU%3E-for-Regex" class="anchor"></a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T<span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#766">source</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into" class="fnname">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="regex" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html> |