<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Regex funktioniert nicht richtig]]></title><description><![CDATA[<p>Ich habe ein input file das in einen string geladen wird. In diesem string sollen dann mit einem Regex matches gesucht werden.<br />
Hier meine implementierung:</p>
<pre><code>void readFile(fs::path filename) {
    ifstream in(filename.string(), ios::in | ios::binary);

    if (in) {
        string content;
        in.seekg(0, ios::end);
        content.resize(in.tellg());
        in.seekg(0, ios::beg);
        in.read(&amp;content[0], content.size());
        in.close();

        searchContent(content);
    }

}

void searchContent(string content) {
     smatch match;
     regex expr(&quot;\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}&quot;);

     while (regex_search(content, match, expr)) {
          for (auto x : match)
               cout &lt;&lt; x &lt;&lt; &quot; &quot;;

           cout &lt;&lt; std::endl;
           content = match.suffix().str();
     }

}
</code></pre>
<p>Das Testfile hat folgende Eintraege:</p>
<p><a href="mailto:abc@gmail.com" rel="nofollow">abc@gmail.com</a> xxx<br />
xxx xx <a href="mailto:test@yahoo.com" rel="nofollow">test@yahoo.com</a> xxx<br />
sss <a href="mailto:a@a.to" rel="nofollow">a@a.to</a></p>
<p>Das Ergbnis ist:</p>
<p><a href="mailto:abc@gmail.com" rel="nofollow">abc@gmail.com</a> xxx<br />
<a href="mailto:test@yahoo.com" rel="nofollow">test@yahoo.com</a> xxx<br />
<a href="mailto:a@a.to" rel="nofollow">a@a.to</a></p>
<p>Das 'xxx' sollten aber nicht mit ausgegeben werden!?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/335113/regex-funktioniert-nicht-richtig</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 21:01:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/335113.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 30 Oct 2015 23:13:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regex funktioniert nicht richtig on Fri, 30 Oct 2015 23:13:31 GMT]]></title><description><![CDATA[<p>Ich habe ein input file das in einen string geladen wird. In diesem string sollen dann mit einem Regex matches gesucht werden.<br />
Hier meine implementierung:</p>
<pre><code>void readFile(fs::path filename) {
    ifstream in(filename.string(), ios::in | ios::binary);

    if (in) {
        string content;
        in.seekg(0, ios::end);
        content.resize(in.tellg());
        in.seekg(0, ios::beg);
        in.read(&amp;content[0], content.size());
        in.close();

        searchContent(content);
    }

}

void searchContent(string content) {
     smatch match;
     regex expr(&quot;\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}&quot;);

     while (regex_search(content, match, expr)) {
          for (auto x : match)
               cout &lt;&lt; x &lt;&lt; &quot; &quot;;

           cout &lt;&lt; std::endl;
           content = match.suffix().str();
     }

}
</code></pre>
<p>Das Testfile hat folgende Eintraege:</p>
<p><a href="mailto:abc@gmail.com" rel="nofollow">abc@gmail.com</a> xxx<br />
xxx xx <a href="mailto:test@yahoo.com" rel="nofollow">test@yahoo.com</a> xxx<br />
sss <a href="mailto:a@a.to" rel="nofollow">a@a.to</a></p>
<p>Das Ergbnis ist:</p>
<p><a href="mailto:abc@gmail.com" rel="nofollow">abc@gmail.com</a> xxx<br />
<a href="mailto:test@yahoo.com" rel="nofollow">test@yahoo.com</a> xxx<br />
<a href="mailto:a@a.to" rel="nofollow">a@a.to</a></p>
<p>Das 'xxx' sollten aber nicht mit ausgegeben werden!?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2473572</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2473572</guid><dc:creator><![CDATA[Cerberus256]]></dc:creator><pubDate>Fri, 30 Oct 2015 23:13:31 GMT</pubDate></item><item><title><![CDATA[Reply to Regex funktioniert nicht richtig on Fri, 30 Oct 2015 23:35:10 GMT]]></title><description><![CDATA[<pre><code>&quot;\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}&quot;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2473576</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2473576</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 30 Oct 2015 23:35:10 GMT</pubDate></item><item><title><![CDATA[Reply to Regex funktioniert nicht richtig on Sat, 31 Oct 2015 06:34:15 GMT]]></title><description><![CDATA[<p>Deshalb gibt es Rawstringliterale.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2473590</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2473590</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sat, 31 Oct 2015 06:34:15 GMT</pubDate></item></channel></rss>