1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>regex_match</title> 5<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../index.html" title="Boost.Regex 5.1.4"> 8<link rel="up" href="../ref.html" title="Reference"> 9<link rel="prev" href="sub_match.html" title="sub_match"> 10<link rel="next" href="regex_search.html" title="regex_search"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="sub_match.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="regex_search.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="boost_regex.ref.regex_match"></a><a class="link" href="regex_match.html" title="regex_match">regex_match</a> 28</h3></div></div></div> 29<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">regex</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 30</pre> 31<p> 32 The algorithm <a class="link" href="regex_match.html" title="regex_match"><code class="computeroutput"><span class="identifier">regex_match</span></code></a> 33 determines whether a given regular expression matches <span class="bold"><strong>all</strong></span> 34 of a given character sequence denoted by a pair of bidirectional-iterators, 35 the algorithm is defined as follows, the main use of this function is data 36 input validation. 37 </p> 38<div class="important"><table border="0" summary="Important"> 39<tr> 40<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../../doc/src/images/important.png"></td> 41<th align="left">Important</th> 42</tr> 43<tr><td align="left" valign="top"><p> 44 Note that the result is true only if the expression matches the <span class="bold"><strong>whole</strong></span> of the input sequence. If you want to search 45 for an expression somewhere within the sequence then use <a class="link" href="regex_search.html" title="regex_search"><code class="computeroutput"><span class="identifier">regex_search</span></code></a>. If you want to match 46 a prefix of the character string then use <a class="link" href="regex_search.html" title="regex_search"><code class="computeroutput"><span class="identifier">regex_search</span></code></a> with the flag match_continuous 47 set. 48 </p></td></tr> 49</table></div> 50<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">BidirectionalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Allocator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span> 51<span class="keyword">bool</span> <span class="identifier">regex_match</span><span class="special">(</span><span class="identifier">BidirectionalIterator</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">BidirectionalIterator</span> <span class="identifier">last</span><span class="special">,</span> 52 <span class="identifier">match_results</span><span class="special"><</span><span class="identifier">BidirectionalIterator</span><span class="special">,</span> <span class="identifier">Allocator</span><span class="special">>&</span> <span class="identifier">m</span><span class="special">,</span> 53 <span class="keyword">const</span> <span class="identifier">basic_regex</span> <span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 54 <span class="identifier">match_flag_type</span> <span class="identifier">flags</span> <span class="special">=</span> <span class="identifier">match_default</span><span class="special">);</span> 55 56<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">BidirectionalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span> 57<span class="keyword">bool</span> <span class="identifier">regex_match</span><span class="special">(</span><span class="identifier">BidirectionalIterator</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">BidirectionalIterator</span> <span class="identifier">last</span><span class="special">,</span> 58 <span class="keyword">const</span> <span class="identifier">basic_regex</span> <span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 59 <span class="identifier">match_flag_type</span> <span class="identifier">flags</span> <span class="special">=</span> <span class="identifier">match_default</span><span class="special">);</span> 60 61<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Allocator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span> 62<span class="keyword">bool</span> <span class="identifier">regex_match</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">charT</span><span class="special">*</span> <span class="identifier">str</span><span class="special">,</span> <span class="identifier">match_results</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">charT</span><span class="special">*,</span> <span class="identifier">Allocator</span><span class="special">>&</span> <span class="identifier">m</span><span class="special">,</span> 63 <span class="keyword">const</span> <span class="identifier">basic_regex</span> <span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 64 <span class="identifier">match_flag_type</span> <span class="identifier">flags</span> <span class="special">=</span> <span class="identifier">match_default</span><span class="special">);</span> 65 66<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">ST</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">SA</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Allocator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span> 67<span class="keyword">bool</span> <span class="identifier">regex_match</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">basic_string</span><span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">ST</span><span class="special">,</span> <span class="identifier">SA</span><span class="special">>&</span> <span class="identifier">s</span><span class="special">,</span> 68 <span class="identifier">match_results</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">basic_string</span><span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">ST</span><span class="special">,</span> <span class="identifier">SA</span><span class="special">>::</span><span class="identifier">const_iterator</span><span class="special">,</span> <span class="identifier">Allocator</span><span class="special">>&</span> <span class="identifier">m</span><span class="special">,</span> 69 <span class="keyword">const</span> <span class="identifier">basic_regex</span> <span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 70 <span class="identifier">match_flag_type</span> <span class="identifier">flags</span> <span class="special">=</span> <span class="identifier">match_default</span><span class="special">);</span> 71 72<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span> 73<span class="keyword">bool</span> <span class="identifier">regex_match</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">charT</span><span class="special">*</span> <span class="identifier">str</span><span class="special">,</span> 74 <span class="keyword">const</span> <span class="identifier">basic_regex</span> <span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 75 <span class="identifier">match_flag_type</span> <span class="identifier">flags</span> <span class="special">=</span> <span class="identifier">match_default</span><span class="special">);</span> 76 77<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">ST</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">SA</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span> 78<span class="keyword">bool</span> <span class="identifier">regex_match</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">basic_string</span><span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">ST</span><span class="special">,</span> <span class="identifier">SA</span><span class="special">>&</span> <span class="identifier">s</span><span class="special">,</span> 79 <span class="keyword">const</span> <span class="identifier">basic_regex</span> <span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 80 <span class="identifier">match_flag_type</span> <span class="identifier">flags</span> <span class="special">=</span> <span class="identifier">match_default</span><span class="special">);</span> 81</pre> 82<h5> 83<a name="boost_regex.ref.regex_match.h0"></a> 84 <span class="phrase"><a name="boost_regex.ref.regex_match.description"></a></span><a class="link" href="regex_match.html#boost_regex.ref.regex_match.description">Description</a> 85 </h5> 86<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">BidirectionalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Allocator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span> 87<span class="keyword">bool</span> <span class="identifier">regex_match</span><span class="special">(</span><span class="identifier">BidirectionalIterator</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">BidirectionalIterator</span> <span class="identifier">last</span><span class="special">,</span> 88 <span class="identifier">match_results</span><span class="special"><</span><span class="identifier">BidirectionalIterator</span><span class="special">,</span> <span class="identifier">Allocator</span><span class="special">>&</span> <span class="identifier">m</span><span class="special">,</span> 89 <span class="keyword">const</span> <span class="identifier">basic_regex</span> <span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 90 <span class="identifier">match_flag_type</span> <span class="identifier">flags</span> <span class="special">=</span> <span class="identifier">match_default</span><span class="special">);</span> 91</pre> 92<p> 93 <span class="bold"><strong>Requires</strong></span>: Type BidirectionalIterator meets 94 the requirements of a Bidirectional Iterator (24.1.4). 95 </p> 96<p> 97 <span class="bold"><strong>Effects</strong></span>: Determines whether there is an 98 exact match between the regular expression <span class="emphasis"><em>e</em></span>, and all 99 of the character sequence [first, last), parameter <span class="emphasis"><em>flags</em></span> 100 (see <a class="link" href="match_flag_type.html" title="match_flag_type"><code class="computeroutput"><span class="identifier">match_flag_type</span></code></a>) 101 is used to control how the expression is matched against the character sequence. 102 Returns true if such a match exists, false otherwise. 103 </p> 104<p> 105 <span class="bold"><strong>Throws</strong></span>: <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code> 106 if the complexity of matching the expression against an N character string 107 begins to exceed O(N<sup>2</sup>), or if the program runs out of stack space while matching 108 the expression (if Boost.Regex is configured in recursive mode), or if the 109 matcher exhausts its permitted memory allocation (if Boost.Regex is configured 110 in non-recursive mode). 111 </p> 112<p> 113 <span class="bold"><strong>Postconditions</strong></span>: If the function returns 114 false, then the effect on parameter <span class="emphasis"><em>m</em></span> is undefined, 115 otherwise the effects on parameter <span class="emphasis"><em>m</em></span> are given in the 116 table: 117 </p> 118<div class="informaltable"><table class="table"> 119<colgroup> 120<col> 121<col> 122</colgroup> 123<thead><tr> 124<th> 125 <p> 126 Element 127 </p> 128 </th> 129<th> 130 <p> 131 Value 132 </p> 133 </th> 134</tr></thead> 135<tbody> 136<tr> 137<td> 138 <p> 139 <code class="computeroutput"><span class="identifier">m</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span></code> 140 </p> 141 </td> 142<td> 143 <p> 144 <code class="computeroutput"><span class="number">1</span> <span class="special">+</span> 145 <span class="identifier">e</span><span class="special">.</span><span class="identifier">mark_count</span><span class="special">()</span></code> 146 </p> 147 </td> 148</tr> 149<tr> 150<td> 151 <p> 152 <code class="computeroutput"><span class="identifier">m</span><span class="special">.</span><span class="identifier">empty</span><span class="special">()</span></code> 153 </p> 154 </td> 155<td> 156 <p> 157 <code class="computeroutput"><span class="keyword">false</span></code> 158 </p> 159 </td> 160</tr> 161<tr> 162<td> 163 <p> 164 <code class="computeroutput"><span class="identifier">m</span><span class="special">.</span><span class="identifier">prefix</span><span class="special">().</span><span class="identifier">first</span></code> 165 </p> 166 </td> 167<td> 168 <p> 169 <code class="computeroutput"><span class="identifier">first</span></code> 170 </p> 171 </td> 172</tr> 173<tr> 174<td> 175 <p> 176 <code class="computeroutput"><span class="identifier">m</span><span class="special">.</span><span class="identifier">prefix</span><span class="special">().</span><span class="identifier">last</span></code> 177 </p> 178 </td> 179<td> 180 <p> 181 <code class="computeroutput"><span class="identifier">first</span></code> 182 </p> 183 </td> 184</tr> 185<tr> 186<td> 187 <p> 188 <code class="computeroutput"><span class="identifier">m</span><span class="special">.</span><span class="identifier">prefix</span><span class="special">().</span><span class="identifier">matched</span></code> 189 </p> 190 </td> 191<td> 192 <p> 193 <code class="computeroutput"><span class="keyword">false</span></code> 194 </p> 195 </td> 196</tr> 197<tr> 198<td> 199 <p> 200 <code class="computeroutput"><span class="identifier">m</span><span class="special">.</span><span class="identifier">suffix</span><span class="special">().</span><span class="identifier">first</span></code> 201 </p> 202 </td> 203<td> 204 <p> 205 <code class="computeroutput"><span class="identifier">last</span></code> 206 </p> 207 </td> 208</tr> 209<tr> 210<td> 211 <p> 212 <code class="computeroutput"><span class="identifier">m</span><span class="special">.</span><span class="identifier">suffix</span><span class="special">().</span><span class="identifier">last</span></code> 213 </p> 214 </td> 215<td> 216 <p> 217 <code class="computeroutput"><span class="identifier">last</span></code> 218 </p> 219 </td> 220</tr> 221<tr> 222<td> 223 <p> 224 <code class="computeroutput"><span class="identifier">m</span><span class="special">.</span><span class="identifier">suffix</span><span class="special">().</span><span class="identifier">matched</span></code> 225 </p> 226 </td> 227<td> 228 <p> 229 <code class="computeroutput"><span class="keyword">false</span></code> 230 </p> 231 </td> 232</tr> 233<tr> 234<td> 235 <p> 236 <code class="computeroutput"><span class="identifier">m</span><span class="special">[</span><span class="number">0</span><span class="special">].</span><span class="identifier">first</span></code> 237 </p> 238 </td> 239<td> 240 <p> 241 <code class="computeroutput"><span class="identifier">first</span></code> 242 </p> 243 </td> 244</tr> 245<tr> 246<td> 247 <p> 248 <code class="computeroutput"><span class="identifier">m</span><span class="special">[</span><span class="number">0</span><span class="special">].</span><span class="identifier">second</span></code> 249 </p> 250 </td> 251<td> 252 <p> 253 <code class="computeroutput"><span class="identifier">last</span></code> 254 </p> 255 </td> 256</tr> 257<tr> 258<td> 259 <p> 260 <code class="computeroutput"><span class="identifier">m</span><span class="special">[</span><span class="number">0</span><span class="special">].</span><span class="identifier">matched</span></code> 261 </p> 262 </td> 263<td> 264 <p> 265 true if a full match was found, and false if it was a partial match 266 (found as a result of the match_partial flag being set). 267 </p> 268 </td> 269</tr> 270<tr> 271<td> 272 <p> 273 <code class="computeroutput"><span class="identifier">m</span><span class="special">[</span><span class="identifier">n</span><span class="special">].</span><span class="identifier">first</span></code> 274 </p> 275 </td> 276<td> 277 <p> 278 For all integers <code class="computeroutput"><span class="identifier">n</span> <span class="special"><</span> <span class="identifier">m</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span></code>, the start of the sequence that 279 matched sub-expression <span class="emphasis"><em>n</em></span>. Alternatively, if 280 sub-expression <span class="emphasis"><em>n</em></span> did not participate in the 281 match, then <code class="computeroutput"><span class="identifier">last</span></code>. 282 </p> 283 </td> 284</tr> 285<tr> 286<td> 287 <p> 288 <code class="computeroutput"><span class="identifier">m</span><span class="special">[</span><span class="identifier">n</span><span class="special">].</span><span class="identifier">second</span></code> 289 </p> 290 </td> 291<td> 292 <p> 293 For all integers <code class="computeroutput"><span class="identifier">n</span> <span class="special"><</span> <span class="identifier">m</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span></code>, the end of the sequence that 294 matched sub-expression <span class="emphasis"><em>n</em></span>. Alternatively, if 295 sub-expression <span class="emphasis"><em>n</em></span> did not participate in the 296 match, then <code class="computeroutput"><span class="identifier">last</span></code>. 297 </p> 298 </td> 299</tr> 300<tr> 301<td> 302 <p> 303 <code class="computeroutput"><span class="identifier">m</span><span class="special">[</span><span class="identifier">n</span><span class="special">].</span><span class="identifier">matched</span></code> 304 </p> 305 </td> 306<td> 307 <p> 308 For all integers <code class="computeroutput"><span class="identifier">n</span> <span class="special"><</span> <span class="identifier">m</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span></code>, true if sub-expression <span class="emphasis"><em>n</em></span> 309 participated in the match, false otherwise. 310 </p> 311 </td> 312</tr> 313</tbody> 314</table></div> 315<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">BidirectionalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span> 316<span class="keyword">bool</span> <span class="identifier">regex_match</span><span class="special">(</span><span class="identifier">BidirectionalIterator</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">BidirectionalIterator</span> <span class="identifier">last</span><span class="special">,</span> 317 <span class="keyword">const</span> <span class="identifier">basic_regex</span> <span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 318 <span class="identifier">match_flag_type</span> <span class="identifier">flags</span> <span class="special">=</span> <span class="identifier">match_default</span><span class="special">);</span> 319</pre> 320<p> 321 <span class="bold"><strong>Effects</strong></span>: Behaves "as if" by constructing 322 an instance of <code class="computeroutput"><span class="identifier">match_results</span><span class="special"><</span><span class="identifier">BidirectionalIterator</span><span class="special">></span> <span class="identifier">what</span></code>, 323 and then returning the result of <code class="computeroutput"><span class="identifier">regex_match</span><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">what</span><span class="special">,</span> <span class="identifier">e</span><span class="special">,</span> 324 <span class="identifier">flags</span><span class="special">)</span></code>. 325 </p> 326<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Allocator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span> 327<span class="keyword">bool</span> <span class="identifier">regex_match</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">charT</span><span class="special">*</span> <span class="identifier">str</span><span class="special">,</span> <span class="identifier">match_results</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">charT</span><span class="special">*,</span> <span class="identifier">Allocator</span><span class="special">>&</span> <span class="identifier">m</span><span class="special">,</span> 328 <span class="keyword">const</span> <span class="identifier">basic_regex</span> <span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 329 <span class="identifier">match_flag_type</span> <span class="identifier">flags</span> <span class="special">=</span> <span class="identifier">match_default</span><span class="special">);</span> 330</pre> 331<p> 332 <span class="bold"><strong>Effects</strong></span>: Returns the result of <code class="computeroutput"><span class="identifier">regex_match</span><span class="special">(</span><span class="identifier">str</span><span class="special">,</span> <span class="identifier">str</span> 333 <span class="special">+</span> <span class="identifier">char_traits</span><span class="special"><</span><span class="identifier">charT</span><span class="special">>::</span><span class="identifier">length</span><span class="special">(</span><span class="identifier">str</span><span class="special">),</span> 334 <span class="identifier">m</span><span class="special">,</span> <span class="identifier">e</span><span class="special">,</span> <span class="identifier">flags</span><span class="special">)</span></code>. 335 </p> 336<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">ST</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">SA</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Allocator</span><span class="special">,</span> 337 <span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span> 338<span class="keyword">bool</span> <span class="identifier">regex_match</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">basic_string</span><span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">ST</span><span class="special">,</span> <span class="identifier">SA</span><span class="special">>&</span> <span class="identifier">s</span><span class="special">,</span> 339 <span class="identifier">match_results</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">basic_string</span><span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">ST</span><span class="special">,</span> <span class="identifier">SA</span><span class="special">>::</span><span class="identifier">const_iterator</span><span class="special">,</span> <span class="identifier">Allocator</span><span class="special">>&</span> <span class="identifier">m</span><span class="special">,</span> 340 <span class="keyword">const</span> <span class="identifier">basic_regex</span> <span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 341 <span class="identifier">match_flag_type</span> <span class="identifier">flags</span> <span class="special">=</span> <span class="identifier">match_default</span><span class="special">);</span> 342</pre> 343<p> 344 <span class="bold"><strong>Effects</strong></span>: Returns the result of <code class="computeroutput"><span class="identifier">regex_match</span><span class="special">(</span><span class="identifier">s</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">m</span><span class="special">,</span> <span class="identifier">e</span><span class="special">,</span> <span class="identifier">flags</span><span class="special">)</span></code>. 345 </p> 346<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span> 347<span class="keyword">bool</span> <span class="identifier">regex_match</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">charT</span><span class="special">*</span> <span class="identifier">str</span><span class="special">,</span> 348 <span class="keyword">const</span> <span class="identifier">basic_regex</span> <span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 349 <span class="identifier">match_flag_type</span> <span class="identifier">flags</span> <span class="special">=</span> <span class="identifier">match_default</span><span class="special">);</span> 350</pre> 351<p> 352 <span class="bold"><strong>Effects</strong></span>: Returns the result of <code class="computeroutput"><span class="identifier">regex_match</span><span class="special">(</span><span class="identifier">str</span><span class="special">,</span> <span class="identifier">str</span> 353 <span class="special">+</span> <span class="identifier">char_traits</span><span class="special"><</span><span class="identifier">charT</span><span class="special">>::</span><span class="identifier">length</span><span class="special">(</span><span class="identifier">str</span><span class="special">),</span> 354 <span class="identifier">e</span><span class="special">,</span> <span class="identifier">flags</span><span class="special">)</span></code>. 355 </p> 356<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">ST</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">SA</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">></span> 357<span class="keyword">bool</span> <span class="identifier">regex_match</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">basic_string</span><span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">ST</span><span class="special">,</span> <span class="identifier">SA</span><span class="special">>&</span> <span class="identifier">s</span><span class="special">,</span> 358 <span class="keyword">const</span> <span class="identifier">basic_regex</span> <span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 359 <span class="identifier">match_flag_type</span> <span class="identifier">flags</span> <span class="special">=</span> <span class="identifier">match_default</span><span class="special">);</span> 360</pre> 361<p> 362 <span class="bold"><strong>Effects</strong></span>: Returns the result of <code class="computeroutput"><span class="identifier">regex_match</span><span class="special">(</span><span class="identifier">s</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">e</span><span class="special">,</span> <span class="identifier">flags</span><span class="special">)</span></code>. 363 </p> 364<h5> 365<a name="boost_regex.ref.regex_match.h1"></a> 366 <span class="phrase"><a name="boost_regex.ref.regex_match.examples"></a></span><a class="link" href="regex_match.html#boost_regex.ref.regex_match.examples">Examples</a> 367 </h5> 368<p> 369 The following example processes an ftp response: 370 </p> 371<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">stdlib</span><span class="special">.</span><span class="identifier">h</span><span class="special">></span> 372<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">regex</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 373<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">string</span><span class="special">></span> 374<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 375 376<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">;</span> 377 378<span class="identifier">regex</span> <span class="identifier">expression</span><span class="special">(</span><span class="string">"([0-9]+)(\\-| |$)(.*)"</span><span class="special">);</span> 379 380<span class="comment">// process_ftp: </span> 381<span class="comment">// on success returns the ftp response code, and fills </span> 382<span class="comment">// msg with the ftp response message. </span> 383<span class="keyword">int</span> <span class="identifier">process_ftp</span><span class="special">(</span><span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">response</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">*</span> <span class="identifier">msg</span><span class="special">)</span> 384<span class="special">{</span> 385 <span class="identifier">cmatch</span> <span class="identifier">what</span><span class="special">;</span> 386 <span class="keyword">if</span><span class="special">(</span><span class="identifier">regex_match</span><span class="special">(</span><span class="identifier">response</span><span class="special">,</span> <span class="identifier">what</span><span class="special">,</span> <span class="identifier">expression</span><span class="special">))</span> 387 <span class="special">{</span> 388 <span class="comment">// what[0] contains the whole string </span> 389 <span class="comment">// what[1] contains the response code </span> 390 <span class="comment">// what[2] contains the separator character </span> 391 <span class="comment">// what[3] contains the text message. </span> 392 <span class="keyword">if</span><span class="special">(</span><span class="identifier">msg</span><span class="special">)</span> 393 <span class="identifier">msg</span><span class="special">-></span><span class="identifier">assign</span><span class="special">(</span><span class="identifier">what</span><span class="special">[</span><span class="number">3</span><span class="special">].</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">what</span><span class="special">[</span><span class="number">3</span><span class="special">].</span><span class="identifier">second</span><span class="special">);</span> 394 <span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">atoi</span><span class="special">(</span><span class="identifier">what</span><span class="special">[</span><span class="number">1</span><span class="special">].</span><span class="identifier">first</span><span class="special">);</span> 395 <span class="special">}</span> 396 <span class="comment">// failure did not match </span> 397 <span class="keyword">if</span><span class="special">(</span><span class="identifier">msg</span><span class="special">)</span> 398 <span class="identifier">msg</span><span class="special">-></span><span class="identifier">erase</span><span class="special">();</span> 399 <span class="keyword">return</span> <span class="special">-</span><span class="number">1</span><span class="special">;</span> 400<span class="special">}</span> 401</pre> 402</div> 403<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 404<td align="left"></td> 405<td align="right"><div class="copyright-footer">Copyright © 1998-2013 John Maddock<p> 406 Distributed under the Boost Software License, Version 1.0. (See accompanying 407 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 408 </p> 409</div></td> 410</tr></table> 411<hr> 412<div class="spirit-nav"> 413<a accesskey="p" href="sub_match.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="regex_search.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 414</div> 415</body> 416</html> 417