Files
hustoj/web/cppreference-zh/chmhelp/cpp-regex-basic_regex-basic_regex.html
2025-08-01 12:57:54 +08:00

163 lines
11 KiB
HTML

<!DOCTYPE html>
<html lang="zh" dir="ltr" class="client-nojs" xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh">
<head><meta http-equiv="x-ua-compatible" content="ie=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>std::basic_regex&lt;CharT,Traits&gt;::basic_regex</title>
<link rel="stylesheet" href="ext.css" />
<link rel="stylesheet" href="site_modules.css" />
</head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_regex_basic_regex_basic_regex skin-cppreference2 action-view cpp-navbar">
<div id="cpp-content-base">
<div id="content"><a id="top"></a>
<h1 id="firstHeading" class="firstHeading"><span style="font-size:0.7em; line-height:130%">std::basic_regex&lt;CharT,Traits&gt;::</span>basic_regex</h1>
<div id="bodyContent">
<div id="contentSub"><span class="subpages">&lt; <a href="cpp.html">cpp</a>&lrm; | <a href="cpp-regex.html">regex</a>&lrm; | <a href="cpp-regex-basic_regex.html">basic regex</a></span></div>
<div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr" xml:lang="zh">
<table class="t-dcl-begin">
<tbody>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp">basic_regex<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span></span></div>
</td>
<td>(1)</td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">explicit</span> basic_regex<span class="br0">(</span> <span class="kw4">const</span> CharT<span class="sy2">*</span> s,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flag_type f <span class="sy1">=</span> <a href="cpp-regex-syntax_option_type.html"><span class="kw2032">std::<span class="me2">regex_constants</span><span class="sy4">::</span><span class="me2">ECMAScript</span></span></a> <span class="br0">)</span><span class="sy4">;</span></span></div>
</td>
<td>(2)</td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp">basic_regex<span class="br0">(</span> <span class="kw4">const</span> CharT<span class="sy2">*</span> s, <a href="cpp-types-size_t.html"><span class="kw100">std::<span class="me2">size_t</span></span></a> count,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;flag_type f <span class="sy1">=</span> <a href="cpp-regex-syntax_option_type.html"><span class="kw2032">std::<span class="me2">regex_constants</span><span class="sy4">::</span><span class="me2">ECMAScript</span></span></a> <span class="br0">)</span><span class="sy4">;</span></span></div>
</td>
<td>(3)</td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp">basic_regex<span class="br0">(</span> <span class="kw4">const</span> basic_regex<span class="sy3">&amp;</span> other <span class="br0">)</span><span class="sy4">;</span></span></div>
</td>
<td>(4)</td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp">basic_regex<span class="br0">(</span> basic_regex<span class="sy3">&amp;&amp;</span> other <span class="br0">)</span> <span class="kw1">noexcept</span><span class="sy4">;</span></span></div>
</td>
<td>(5)</td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;</span> <span class="kw1">class</span> ST, <span class="kw1">class</span> SA <span class="sy1">&gt;</span><br /></span>
<p><span class="kw1">explicit</span> basic_regex<span class="br0">(</span> <span class="kw4">const</span> <a href="cpp-string-basic_string.html"><span class="kw1228">std::<span class="me2">basic_string</span></span></a><span class="sy1">&lt;</span>CharT,ST,SA<span class="sy1">&gt;</span><span class="sy3">&amp;</span> str,<br /></p>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flag_type f <span class="sy1">=</span> <a href="cpp-regex-syntax_option_type.html"><span class="kw2032">std::<span class="me2">regex_constants</span><span class="sy4">::</span><span class="me2">ECMAScript</span></span></a> <span class="br0">)</span><span class="sy4">;</span></div>
</td>
<td>(6)</td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span><span class="sy1">&lt;</span> <span class="kw1">class</span> ForwardIt <span class="sy1">&gt;</span><br /></span>
<p>basic_regex<span class="br0">(</span> ForwardIt first, ForwardIt last,<br /></p>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;flag_type f <span class="sy1">=</span> <a href="cpp-regex-syntax_option_type.html"><span class="kw2032">std::<span class="me2">regex_constants</span><span class="sy4">::</span><span class="me2">ECMAScript</span></span></a> <span class="br0">)</span><span class="sy4">;</span></div>
</td>
<td>(7)</td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl t-since-cxx11">
<td>
<div><span class="mw-geshi cpp source-cpp">basic_regex<span class="br0">(</span> <a href="cpp-utility-initializer_list.html"><span class="kw960">std::<span class="me2">initializer_list</span></span></a><span class="sy1">&lt;</span>CharT<span class="sy1">&gt;</span> init,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;flag_type f <span class="sy1">=</span> <a href="cpp-regex-syntax_option_type.html"><span class="kw2032">std::<span class="me2">regex_constants</span><span class="sy4">::</span><span class="me2">ECMAScript</span></span></a> <span class="br0">)</span><span class="sy4">;</span></span></div>
</td>
<td>(8)</td>
<td><span class="t-mark-rev t-since-cxx11">(C++11 &#36215;)</span></td>
</tr>
<tr class="t-dcl-sep">
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>&#20174;&#25353;&#29031;&#26631;&#24535; <code>f</code> &#36716;&#35793;&#30340;&#23383;&#31526;&#24207;&#21015;&#26500;&#36896;&#26032;&#30340;&#27491;&#21017;&#34920;&#36798;&#24335;&#12290;</p>
<div class="t-li1"><span class="t-li">1)</span> &#40664;&#35748;&#26500;&#36896;&#20989;&#25968;&#12290;&#26500;&#36896;&#23558;&#19981;&#21305;&#37197;&#20869;&#23481;&#30340;&#31354;&#27491;&#21017;&#34920;&#36798;&#24335;&#12290;</div>
<div class="t-li1"><span class="t-li">2)</span> &#20174;&#31354;&#32456;&#27490;&#23383;&#31526;&#20018; <code>s</code> &#26500;&#36896;&#27491;&#21017;&#34920;&#36798;&#24335;&#12290;</div>
<div class="t-li1"><span class="t-li">3)</span> &#20174; <code>s</code> &#25152;&#25351;&#21521;&#30340; <code>count</code> &#20010;&#30340;&#23383;&#31526;&#24207;&#21015;&#26500;&#36896;&#27491;&#21017;&#34920;&#36798;&#24335;&#12290;</div>
<div class="t-li1"><span class="t-li">4)</span> &#22797;&#21046;&#26500;&#36896;&#20989;&#25968;&#12290;&#36890;&#36807;&#22797;&#21046; <code>other</code> &#26500;&#36896;&#27491;&#21017;&#34920;&#36798;&#24335;&#12290;</div>
<div class="t-li1"><span class="t-li">5)</span> &#31227;&#21160;&#26500;&#36896;&#20989;&#25968;&#12290;&#29992;&#31227;&#21160;&#35821;&#20041;&#26500;&#36896;&#25317;&#26377; <code>other</code> &#20869;&#23481;&#30340;&#27491;&#21017;&#34920;&#36798;&#24335;&#12290;</div>
<div class="t-li1"><span class="t-li">6)</span> &#20174; string <code>str</code> &#26500;&#36896;&#27491;&#21017;&#34920;&#36798;&#24335;&#12290;</div>
<div class="t-li1"><span class="t-li">7)</span> &#33539;&#22260;&#26500;&#36896;&#20989;&#25968;&#12290;&#26500;&#36896;&#25317;&#26377;&#33539;&#22260; <code>[first, last)</code> &#20869;&#23481;&#30340;&#27491;&#21017;&#34920;&#36798;&#24335;&#12290;</div>
<div class="t-li1"><span class="t-li">8)</span> initializer_list &#26500;&#36896;&#20989;&#25968;&#12290;&#26500;&#36896;&#25317;&#26377; initializer_list <code>init</code> &#20869;&#23481;&#30340;&#27491;&#21017;&#34920;&#36798;&#24335;&#12290;</div>
<h3><span class="mw-headline" id=".E5.8F.82.E6.95.B0">&#21442;&#25968;</span></h3>
<table class="t-par-begin">
<tr class="t-par">
<td>s</td>
<td>-</td>
<td>&#25351;&#21521;&#31354;&#32456;&#27490;&#23383;&#31526;&#20018;&#30340;&#25351;&#38024;</td>
</tr>
<tr class="t-par">
<td>count</td>
<td>-</td>
<td>&#29992;&#20110;&#21021;&#22987;&#21270; regex &#30340;&#23383;&#31526;&#24207;&#21015;&#38271;&#24230;</td>
</tr>
<tr class="t-par">
<td>first, last</td>
<td>-</td>
<td>&#29992;&#20110;&#21021;&#22987;&#21270; regex &#30340;&#23383;&#31526;&#24207;&#21015;&#33539;&#22260;</td>
</tr>
<tr class="t-par">
<td>str</td>
<td>-</td>
<td>&#29992;&#20316;&#28304;&#21021;&#22987;&#21270; regex &#30340; basic_string</td>
</tr>
<tr class="t-par">
<td>other</td>
<td>-</td>
<td>&#29992;&#20316;&#28304;&#21021;&#22987;&#21270; regex &#30340;&#21478;&#19968; regex</td>
</tr>
<tr class="t-par">
<td>init</td>
<td>-</td>
<td>&#29992;&#20110;&#21021;&#22987;&#21270; regex &#30340; initializer_list</td>
</tr>
<tr class="t-par">
<td>f</td>
<td>-</td>
<td>&#29992;&#20110;&#25351;&#24341;&#36716;&#35793;&#23383;&#31526;&#24207;&#21015;&#20026;&#27491;&#21017;&#34920;&#36798;&#24335;&#30340;&#26631;&#24535;</td>
</tr>
<tr class="t-par-hitem">
<td colspan="3">&#31867;&#22411;&#35201;&#27714;</td>
</tr>
<tr class="t-par-req">
<td colspan="3">-
<div class="spacer"></div>
<code>ForwardIt</code> &#24517;&#39035;&#28385;&#36275;<a href="cpp-named_req-ForwardIterator.html"><span style="font-style:italic">&#32769;&#24335;&#21521;&#21069;&#36845;&#20195;&#22120;</span> <span style="font-family: Georgia, &#39;DejaVu Serif&#39;, serif; font-style:italic">(LegacyForwardIterator)</span></a> &#30340;&#35201;&#27714;&#12290;</td>
</tr>
</table>
<h3><span class="mw-headline" id=".E5.BC.82.E5.B8.B8">&#24322;&#24120;</span></h3>
<div class="t-li1"><span class="t-li">1)</span> &#21487;&#33021;&#25243;&#20986;&#23454;&#29616;&#23450;&#20041;&#30340;&#24322;&#24120;&#12290;</div>
<div class="t-li1"><span class="t-li">2-3)</span> &#33509;&#25552;&#20379;&#30340;&#27491;&#21017;&#34920;&#36798;&#24335;&#38750;&#27861;&#21017;&#20026; <span class="t-lc"><a href="cpp-regex-regex_error.html">std::regex_error</a></span> &#12290;</div>
<div class="t-li1"><span class="t-li">4)</span> &#21487;&#33021;&#25243;&#20986;&#23454;&#29616;&#23450;&#20041;&#30340;&#24322;&#24120;&#12290;</div>
<div class="t-li1"><span class="t-li">6-8)</span> &#33509;&#25552;&#20379;&#30340;&#27491;&#21017;&#34920;&#36798;&#24335;&#38750;&#27861;&#21017;&#20026; <span class="t-lc"><a href="cpp-regex-regex_error.html">std::regex_error</a></span> &#12290;</div>
<h3><span class="mw-headline" id=".E7.A4.BA.E4.BE.8B">&#31034;&#20363;</span></h3>
<table class="metadata plainlinks ambox mbox-small-left ambox-notice" style="">
<tr>
<td class="mbox-empty-cell"></td>
<td class="mbox-text" style="">&#26412;&#33410;&#26410;&#23436;&#25104;<br />
&#21407;&#22240;&#65306;&#26242;&#26080;&#31034;&#20363;</td>
</tr>
</table>
</div>
<div class="visualClear"></div>
</div>
</div>
</div>
</body>
</html>