Searching for pattern inside a string
<p>Is it possible to search for certain patterns inside std::string in C++?</p>

<p>I am aware of <code>find()</code>, <code>find_first_of()</code> and so on, but I am looking for something more advanced.</p>

<p>For example, take this XML line: <code>&lt;book category="fantasy"&gt;Hitchhiker's guide to the galaxy &lt;/book&gt;</code></p>

<p>If I want to parse it using <code>find()</code> I could do it as follows:</p>

<pre><code>string line = "&lt;book category=\"fantasy\"&gt;Hitchhiker's guide to the galaxy &lt;/book&gt;"

size_t position = line.find('&gt;');
std::string tmp = line.substr(0,position);
position = tmp.find(' ');
std::string node_name = tmp.substr(0, position);
std::string parameters = tmp.substr(position+1);

...
</code></pre>

<p>This feels very "grindy" and inefficient. It would also fail, if I had multiple tags nested inside each other, like this:</p>

<p><code>&lt;bookstore&gt;&lt;book category=\"fantasy\"&gt;Hitchhiker's guide to the galaxy &lt;/book&gt;&lt;/bookstore&gt;</code></p>

<p>Is there a way to search for pattern, as in search for <code>&lt;*&gt;</code> where <code>*</code> represents any amount of characters of any value, getting the value of <code>*</code>, splitting it to parameters and node name, then searching for <code>&lt;/nodename&gt;</code> and getting the value inbetween <code>&lt;nodename&gt;</code> and <code>&lt;/nodename&gt;</code> ?</p>
