| <!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 arbitrary bytes."><meta name="keywords" content="rust, rustlang, rust-lang, Regex"><title>Regex in regex::bytes - 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::bytes</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 href="index.html">bytes</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_bytes.rs.html#108">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 arbitrary bytes.</p> |
| <p>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>Like the <code>Regex</code> type in the parent module, matches with this regex return |
| byte offsets into the search text. <strong>Unlike</strong> the parent <code>Regex</code> type, |
| these byte offsets may not correspond to UTF-8 sequence boundaries since |
| the regexes in this module can match arbitrary bytes.</p> |
| </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_bytes.rs.html#144-556">source</a><a href="#impl-Regex" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.Regex.html" title="struct regex::bytes::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_bytes.rs.html#149-151">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a>(re: &str) -> Result<<a class="struct" href="struct.Regex.html" title="struct regex::bytes::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_bytes.rs.html#172-174">source</a><h4 class="code-header">pub fn <a href="#method.is_match" class="fnname">is_match</a>(&self, text: &[u8]) -> bool</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 ASCII word |
| bytes:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>text = <span class="string">b"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_bytes.rs.html#196-198">source</a><h4 class="code-header">pub fn <a href="#method.find" class="fnname">find</a><'t>(&self, text: &'t [u8]) -> Option<<a class="struct" href="struct.Match.html" title="struct regex::bytes::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 |
| ASCII word bytes:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>text = <span class="string">b"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(), mat.end()), (<span class="number">2</span>, <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_bytes.rs.html#218-220">source</a><h4 class="code-header">pub fn <a href="#method.find_iter" class="fnname">find_iter</a><'r, 't>(&'r self, text: &'t [u8]) -> <a class="struct" href="struct.Matches.html" title="struct regex::bytes::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::bytes::Matches">Matches</a><'r, 't></span><code class="content"><span class="where fmt-newline">impl<'r, 't> Iterator for <a class="struct" href="struct.Matches.html" title="struct regex::bytes::Matches">Matches</a><'r, 't></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = <a class="struct" href="struct.Match.html" title="struct regex::bytes::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 ASCII |
| word bytes:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>text = <span class="string">b"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_bytes.rs.html#285-287">source</a><h4 class="code-header">pub fn <a href="#method.captures" class="fnname">captures</a><'t>(&self, text: &'t [u8]) -> Option<<a class="struct" href="struct.Captures.html" title="struct regex::bytes::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"><a href="#examples">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">b"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_bytes(), <span class="kw-2">&</span><span class="string">b"Citizen Kane"</span>[..]); |
| <span class="macro">assert_eq!</span>(caps.get(<span class="number">2</span>).unwrap().as_bytes(), <span class="kw-2">&</span><span class="string">b"1941"</span>[..]); |
| <span class="macro">assert_eq!</span>(caps.get(<span class="number">0</span>).unwrap().as_bytes(), <span class="kw-2">&</span><span class="string">b"'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">b"Citizen Kane"</span>); |
| <span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="number">2</span>], <span class="string">b"1941"</span>); |
| <span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="number">0</span>], <span class="string">b"'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">b"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_bytes(), <span class="string">b"Citizen Kane"</span>); |
| <span class="macro">assert_eq!</span>(caps.name(<span class="string">"year"</span>).unwrap().as_bytes(), <span class="string">b"1941"</span>); |
| <span class="macro">assert_eq!</span>(caps.get(<span class="number">0</span>).unwrap().as_bytes(), <span class="kw-2">&</span><span class="string">b"'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">b"Citizen Kane"</span>); |
| <span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="string">"year"</span>], <span class="string">b"1941"</span>); |
| <span class="macro">assert_eq!</span>(<span class="kw-2">&</span>caps[<span class="number">0</span>], <span class="string">b"'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_bytes.rs.html#315-320">source</a><h4 class="code-header">pub fn <a href="#method.captures_iter" class="fnname">captures_iter</a><'r, 't>(&'r self, text: &'t [u8]) -> <a class="struct" href="struct.CaptureMatches.html" title="struct regex::bytes::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::bytes::CaptureMatches">CaptureMatches</a><'r, 't></span><code class="content"><span class="where fmt-newline">impl<'r, 't> Iterator for <a class="struct" href="struct.CaptureMatches.html" title="struct regex::bytes::CaptureMatches">CaptureMatches</a><'r, 't></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = <a class="struct" href="struct.Captures.html" title="struct regex::bytes::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">b"'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="kw">let </span>title = str::from_utf8(<span class="kw-2">&</span>caps[<span class="string">"title"</span>]).unwrap(); |
| <span class="kw">let </span>year = str::from_utf8(<span class="kw-2">&</span>caps[<span class="string">"year"</span>]).unwrap(); |
| <span class="macro">println!</span>(<span class="string">"Movie: {:?}, Released: {:?}"</span>, title, year); |
| } |
| <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_bytes.rs.html#342-344">source</a><h4 class="code-header">pub fn <a href="#method.split" class="fnname">split</a><'r, 't>(&'r self, text: &'t [u8]) -> <a class="struct" href="struct.Split.html" title="struct regex::bytes::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::bytes::Split">Split</a><'r, 't></span><code class="content"><span class="where fmt-newline">impl<'r, 't> Iterator for <a class="struct" href="struct.Split.html" title="struct regex::bytes::Split">Split</a><'r, 't></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = &'t [u8];</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>[u8]> = re.split(<span class="string">b"a b \t c\td e"</span>).collect(); |
| <span class="macro">assert_eq!</span>(fields, <span class="macro">vec!</span>[ |
| <span class="kw-2">&</span><span class="string">b"a"</span>[..], <span class="kw-2">&</span><span class="string">b"b"</span>[..], <span class="kw-2">&</span><span class="string">b"c"</span>[..], <span class="kw-2">&</span><span class="string">b"d"</span>[..], <span class="kw-2">&</span><span class="string">b"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_bytes.rs.html#366-372">source</a><h4 class="code-header">pub fn <a href="#method.splitn" class="fnname">splitn</a><'r, 't>(&'r self, text: &'t [u8], limit: usize) -> <a class="struct" href="struct.SplitN.html" title="struct regex::bytes::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::bytes::SplitN">SplitN</a><'r, 't></span><code class="content"><span class="where fmt-newline">impl<'r, 't> Iterator for <a class="struct" href="struct.SplitN.html" title="struct regex::bytes::SplitN">SplitN</a><'r, 't></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = &'t [u8];</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>[u8]> = re.splitn(<span class="string">b"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="kw-2">&</span><span class="string">b"Hey"</span>[..], <span class="kw-2">&</span><span class="string">b"How"</span>[..], <span class="kw-2">&</span><span class="string">b"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_bytes.rs.html#482-488">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::bytes::Replacer">Replacer</a>>(&self, text: &'t [u8], rep: R) -> Cow<'t, [u8]></h4></section></summary><div class="docblock"><p>Replaces the leftmost-first match with the replacement provided. The |
| replacement can be a regular byte 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 byte string.</p> |
| <p>If no match is found, then a copy of the byte 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-1"><a href="#examples-1">Examples</a></h5> |
| <p>Note that this function is polymorphic with respect to the replacement. |
| In typical usage, this can just be a normal byte 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">b"1078910"</span>, <span class="kw-2">&</span><span class="string">b""</span>[..]), <span class="kw-2">&</span><span class="string">b"1010"</span>[..]);</code></pre></div> |
| <p>But anything satisfying the <code>Replacer</code> trait will work. For example, a |
| closure of type <code>|&Captures| -> Vec<u8></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">b"Springsteen, Bruce"</span>, |caps: <span class="kw-2">&</span>Captures| { |
| <span class="kw">let </span><span class="kw-2">mut </span>replacement = caps[<span class="number">2</span>].to_owned(); |
| replacement.push(<span class="string">b' '</span>); |
| replacement.extend(<span class="kw-2">&</span>caps[<span class="number">1</span>]); |
| replacement |
| }); |
| <span class="macro">assert_eq!</span>(result, <span class="kw-2">&</span><span class="string">b"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">b"Springsteen, Bruce"</span>, <span class="kw-2">&</span><span class="string">b"$first $last"</span>[..]); |
| <span class="macro">assert_eq!</span>(result, <span class="kw-2">&</span><span class="string">b"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">b"deep fried"</span>, <span class="kw-2">&</span><span class="string">b"${first}_$second"</span>[..]); |
| <span class="macro">assert_eq!</span>(result, <span class="kw-2">&</span><span class="string">b"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::bytes::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">b"Springsteen, Bruce"</span>, NoExpand(<span class="string">b"$2 $last"</span>)); |
| <span class="macro">assert_eq!</span>(result, <span class="kw-2">&</span><span class="string">b"$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_bytes.rs.html#496-502">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::bytes::Replacer">Replacer</a>>(<br> &self,<br> text: &'t [u8],<br> rep: R<br>) -> Cow<'t, [u8]></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 text.</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_bytes.rs.html#510-555">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::bytes::Replacer">Replacer</a>>(<br> &self,<br> text: &'t [u8],<br> limit: usize,<br> rep: R<br>) -> Cow<'t, [u8]></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 text.</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_bytes.rs.html#559-702">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::bytes::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_bytes.rs.html#588-590">source</a><h4 class="code-header">pub fn <a href="#method.shortest_match" class="fnname">shortest_match</a>(&self, text: &[u8]) -> Option<usize></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">b"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_bytes.rs.html#598-604">source</a><h4 class="code-header">pub fn <a href="#method.shortest_match_at" class="fnname">shortest_match_at</a>(&self, text: &[u8], start: usize) -> Option<usize></h4></section></summary><div class="docblock"><p>Returns the same as shortest_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.is_match_at" class="method has-srclink"><a class="srclink rightside" href="../../src/regex/re_bytes.rs.html#612-614">source</a><h4 class="code-header">pub fn <a href="#method.is_match_at" class="fnname">is_match_at</a>(&self, text: &[u8], start: usize) -> bool</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_bytes.rs.html#622-631">source</a><h4 class="code-header">pub fn <a href="#method.find_at" class="fnname">find_at</a><'t>(&self, text: &'t [u8], start: usize) -> Option<<a class="struct" href="struct.Match.html" title="struct regex::bytes::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_bytes.rs.html#639-650">source</a><h4 class="code-header">pub fn <a href="#method.captures_at" class="fnname">captures_at</a><'t>(<br> &self,<br> text: &'t [u8],<br> start: usize<br>) -> Option<<a class="struct" href="struct.Captures.html" title="struct regex::bytes::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_bytes.rs.html#662-668">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::bytes::CaptureLocations">CaptureLocations</a>,<br> text: &'t [u8]<br>) -> Option<<a class="struct" href="struct.Match.html" title="struct regex::bytes::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_bytes.rs.html#676-686">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::bytes::CaptureLocations">CaptureLocations</a>,<br> text: &'t [u8],<br> start: usize<br>) -> Option<<a class="struct" href="struct.Match.html" title="struct regex::bytes::Match">Match</a><'t>></h4></section></summary><div class="docblock"><p>Returns the same as <code>captures_read</code>, 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_bytes.rs.html#705-775">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::bytes::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_bytes.rs.html#707-709">source</a><h4 class="code-header">pub fn <a href="#method.as_str" class="fnname">as_str</a>(&self) -> &str</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_bytes.rs.html#712-714">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::bytes::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::bytes::CaptureNames">CaptureNames</a><'r></span><code class="content"><span class="where fmt-newline">impl<'r> Iterator for <a class="struct" href="struct.CaptureNames.html" title="struct regex::bytes::CaptureNames">CaptureNames</a><'r></span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = Option<&'r str>;</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_bytes.rs.html#717-719">source</a><h4 class="code-header">pub fn <a href="#method.captures_len" class="fnname">captures_len</a>(&self) -> usize</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_bytes.rs.html#757-759">source</a><h4 class="code-header">pub fn <a href="#method.static_captures_len" class="fnname">static_captures_len</a>(&self) -> Option<usize></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::bytes::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_bytes.rs.html#763-765">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::bytes::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_bytes.rs.html#107">source</a><a href="#impl-Clone-for-Regex" class="anchor"></a><h3 class="code-header">impl Clone for <a class="struct" href="struct.Regex.html" title="struct regex::bytes::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_bytes.rs.html#107">source</a><a href="#method.clone" class="anchor"></a><h4 class="code-header">fn <a class="fnname">clone</a>(&self) -> <a class="struct" href="struct.Regex.html" title="struct regex::bytes::Regex">Regex</a></h4></section></summary><div class='docblock'>Returns a copy of the value. <a>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="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.clone_from" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">clone_from</a>(&mut self, source: &Self)</h4></section></summary><div class='docblock'>Performs copy-assignment from <code>source</code>. <a>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_bytes.rs.html#117-122">source</a><a href="#impl-Debug-for-Regex" class="anchor"></a><h3 class="code-header">impl Debug for <a class="struct" href="struct.Regex.html" title="struct regex::bytes::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_bytes.rs.html#119-121">source</a><a href="#method.fmt-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&self, f: &mut Formatter<'_>) -> Result</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_bytes.rs.html#110-115">source</a><a href="#impl-Display-for-Regex" class="anchor"></a><h3 class="code-header">impl Display for <a class="struct" href="struct.Regex.html" title="struct regex::bytes::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_bytes.rs.html#112-114">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&self, f: &mut Formatter<'_>) -> Result</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_bytes.rs.html#134-141">source</a><a href="#impl-FromStr-for-Regex" class="anchor"></a><h3 class="code-header">impl FromStr for <a class="struct" href="struct.Regex.html" title="struct regex::bytes::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_bytes.rs.html#138-140">source</a><a href="#method.from_str" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from_str</a>(s: &str) -> Result<<a class="struct" href="struct.Regex.html" title="struct regex::bytes::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 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 RefUnwindSafe for <a class="struct" href="struct.Regex.html" title="struct regex::bytes::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 Send for <a class="struct" href="struct.Regex.html" title="struct regex::bytes::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 Sync for <a class="struct" href="struct.Regex.html" title="struct regex::bytes::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 Unpin for <a class="struct" href="struct.Regex.html" title="struct regex::bytes::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 UnwindSafe for <a class="struct" href="struct.Regex.html" title="struct regex::bytes::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 href="#impl-Any-for-Regex" class="anchor"></a><h3 class="code-header">impl<T> Any for T<span class="where fmt-newline">where<br> T: 'static + ?Sized,</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 href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a class="fnname">type_id</a>(&self) -> TypeId</h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a>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 href="#impl-Borrow%3CT%3E-for-Regex" class="anchor"></a><h3 class="code-header">impl<T> Borrow<T> for T<span class="where fmt-newline">where<br> T: ?Sized,</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="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow</a>(&self) -> &T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a>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 href="#impl-BorrowMut%3CT%3E-for-Regex" class="anchor"></a><h3 class="code-header">impl<T> BorrowMut<T> for T<span class="where fmt-newline">where<br> T: ?Sized,</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="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow_mut</a>(&mut self) -> &mut T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a>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 href="#impl-From%3CT%3E-for-Regex" class="anchor"></a><h3 class="code-header">impl<T> From<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="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a 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 href="#impl-Into%3CU%3E-for-Regex" class="anchor"></a><h3 class="code-header">impl<T, U> Into<U> for T<span class="where fmt-newline">where<br> U: From<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="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a 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>[From]<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 href="#impl-ToOwned-for-Regex" class="anchor"></a><h3 class="code-header">impl<T> ToOwned for T<span class="where fmt-newline">where<br> T: Clone,</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 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 href="#method.to_owned" class="anchor"></a><h4 class="code-header">fn <a class="fnname">to_owned</a>(&self) -> T</h4></section></summary><div class='docblock'>Creates owned data from borrowed data, usually by cloning. <a>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 href="#method.clone_into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">clone_into</a>(&self, target: &mut T)</h4></section></summary><div class='docblock'>Uses borrowed data to replace owned data, usually by cloning. <a>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 href="#impl-ToString-for-Regex" class="anchor"></a><h3 class="code-header">impl<T> ToString for T<span class="where fmt-newline">where<br> T: Display + ?Sized,</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 href="#method.to_string" class="anchor"></a><h4 class="code-header">default fn <a class="fnname">to_string</a>(&self) -> String</h4></section></summary><div class='docblock'>Converts the given value to a <code>String</code>. <a>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 href="#impl-TryFrom%3CU%3E-for-Regex" class="anchor"></a><h3 class="code-header">impl<T, U> TryFrom<U> for T<span class="where fmt-newline">where<br> U: Into<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 class="associatedtype">Error</a> = Infallible</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="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_from</a>(value: U) -> Result<T, <T as TryFrom<U>>::Error></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 href="#impl-TryInto%3CU%3E-for-Regex" class="anchor"></a><h3 class="code-header">impl<T, U> TryInto<U> for T<span class="where fmt-newline">where<br> U: TryFrom<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 class="associatedtype">Error</a> = <U as TryFrom<T>>::Error</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="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_into</a>(self) -> Result<U, <U as TryFrom<T>>::Error></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> |