<?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[Suche regulären ausdruck für Id Liste]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>die Frage ist wahrscheinlich trivial, aber ich kenne mich leider schlecht mit regulären Ausdrücken aus und stehe da total auf dem Schlauch und bitte daher um Nachsicht.</p>
<p>Ich habe eine Textzeile die wie folgt aussieht:<br />
(0x0020011c,IDs:2,3,4,8,15,2a;0x00000003)<br />
Die drei Teile nenne ich nachfolgend <em>IDhex1</em>, <em>ID-List</em>, <em>IDhex2</em>.</p>
<p><em>IDhex1</em> und <em>IDhex2</em> sind Hexadezimalwerte fester länge. <em>ID-List</em> ist eine liste von Hexadezimalwerten mit praktisch beliebiger Länge.</p>
<p>Der Teil <em>ID-List</em> ist optional, daher kann das auch folgendermaßen aussehen:<br />
(0x0020011c;0x00000003)</p>
<p>Ich interessieren mich für die Teile <em>IDhex1</em> und <em>ID-List</em>, wobei bei ID-List nur die Liste, also der teil nach dem &quot;IDs:&quot; interessant ist. Wie sähe ein std::regex aus, mit dem ich beides extrahieren kann?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/327192/suche-regulären-ausdruck-für-id-liste</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Jul 2026 20:22:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/327192.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 28 Jul 2014 10:28:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Suche regulären ausdruck für Id Liste on Mon, 28 Jul 2014 10:28:26 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>die Frage ist wahrscheinlich trivial, aber ich kenne mich leider schlecht mit regulären Ausdrücken aus und stehe da total auf dem Schlauch und bitte daher um Nachsicht.</p>
<p>Ich habe eine Textzeile die wie folgt aussieht:<br />
(0x0020011c,IDs:2,3,4,8,15,2a;0x00000003)<br />
Die drei Teile nenne ich nachfolgend <em>IDhex1</em>, <em>ID-List</em>, <em>IDhex2</em>.</p>
<p><em>IDhex1</em> und <em>IDhex2</em> sind Hexadezimalwerte fester länge. <em>ID-List</em> ist eine liste von Hexadezimalwerten mit praktisch beliebiger Länge.</p>
<p>Der Teil <em>ID-List</em> ist optional, daher kann das auch folgendermaßen aussehen:<br />
(0x0020011c;0x00000003)</p>
<p>Ich interessieren mich für die Teile <em>IDhex1</em> und <em>ID-List</em>, wobei bei ID-List nur die Liste, also der teil nach dem &quot;IDs:&quot; interessant ist. Wie sähe ein std::regex aus, mit dem ich beides extrahieren kann?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2410800</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2410800</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Mon, 28 Jul 2014 10:28:26 GMT</pubDate></item><item><title><![CDATA[Reply to Suche regulären ausdruck für Id Liste on Mon, 28 Jul 2014 12:21:02 GMT]]></title><description><![CDATA[<p>Hausaufgaben? Was zahlst du?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2410831</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2410831</guid><dc:creator><![CDATA[oenone]]></dc:creator><pubDate>Mon, 28 Jul 2014 12:21:02 GMT</pubDate></item><item><title><![CDATA[Reply to Suche regulären ausdruck für Id Liste on Mon, 28 Jul 2014 12:56:22 GMT]]></title><description><![CDATA[<p>oenone schrieb:</p>
<blockquote>
<p>Hausaufgaben? Was zahlst du?</p>
</blockquote>
<p>Ich gehe lange nicht mehr zur Schule und als &quot;Gegenleistung&quot; kann ich leider nur anbieten, hier weiterhin die ein oder andere Frage zu beantworten (Was ich ohnehin machen werde, egal ob ich eine Antwort bekomme oder nicht). Wenn das nicht reicht ist das halt so.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2410838</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2410838</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Mon, 28 Jul 2014 12:56:22 GMT</pubDate></item><item><title><![CDATA[Reply to Suche regulären ausdruck für Id Liste on Mon, 28 Jul 2014 13:10:43 GMT]]></title><description><![CDATA[<blockquote>
<p>Was zahlst du?</p>
</blockquote>
<p>Wenn du nicht die Motivation hast es ohne Gegenleistung zu tun, hast du in diesem Forum eine merkwürdige Doppelmoral. Die Frage hat m.E.n. mehr als genug Eigeninitiative.</p>
<p>Ich schlage mal</p>
<pre><code>#include &lt;regex&gt;
#include &lt;iostream&gt;

int main()
{
	std::regex reg( R&quot;(\((0[xX][0-9a-fA-F]+)(,IDs:([0-9a-f]+(,[0-9a-f]+)*))?;.+\))&quot; );

	std::string str = &quot;(0x0020011c,IDs:2,3,4,8,15,2a;0x00000003)&quot;;

	std::smatch match;
	if (std::regex_match(str, match, reg))
		std::cout &lt;&lt; match[1] &lt;&lt; ' ' &lt;&lt; match[3];
}
</code></pre>
<p>vor, aber wie bereits anderswo erwähnt bin ich kein Regex-Experte; warte also lieber noch auf eine saubere Lösung.</p>
<p>Edit: <a href="http://coliru.stacked-crooked.com/" rel="nofollow">Hier</a> noch mal der Stacked-Crooked Link.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2410841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2410841</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 28 Jul 2014 13:10:43 GMT</pubDate></item><item><title><![CDATA[Reply to Suche regulären ausdruck für Id Liste on Mon, 28 Jul 2014 13:38:28 GMT]]></title><description><![CDATA[<p>Wie sieht es mit Leerzeichen aus? Nach Vorlage hätte ich es so interpretiert:</p>
<pre><code>&quot;\\(0[xX][0-9a-fA-F]{8}(,IDs:[0-9a-fA-F]+(,[0-9a-fA-F]+)*)?;0[xX][0-9a-fA-F]{8}\\)&quot;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2410846</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2410846</guid><dc:creator><![CDATA[mal so]]></dc:creator><pubDate>Mon, 28 Jul 2014 13:38:28 GMT</pubDate></item><item><title><![CDATA[Reply to Suche regulären ausdruck für Id Liste on Mon, 28 Jul 2014 13:49:59 GMT]]></title><description><![CDATA[<p>Ich denke das sieht schon nicht so schlecht aus soweit ich das nachvollziehen kann, aber zu den IDs: Ich denke die ID liste könnte theoretisch auch leer sein, also etwa (0x0020011c,IDs:;0x00000003) auch interesiert mich nur die Liste ansich, also bei IDs:2,3,4,8,15,2a nur 2,3,4,8,15,2a.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2410847</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2410847</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Mon, 28 Jul 2014 13:49:59 GMT</pubDate></item><item><title><![CDATA[Reply to Suche regulären ausdruck für Id Liste on Mon, 28 Jul 2014 16:09:44 GMT]]></title><description><![CDATA[<p>Mein Ansatz basierend auf Arcoths Vorarbeit:</p>
<pre><code class="language-cpp">#include &lt;regex&gt;
#include &lt;iostream&gt;

int main() {
  std::regex reg(
      R&quot;(\((0x[\da-f]+)(?:,IDs:([\da-f]+(?:,[\da-f]+)*)?)?;(0x[\da-f]+)\))&quot;,
      std::regex_constants::icase);

  std::smatch match;
  for (auto str : { &quot;(0x0020011c,IDs:2,3,4,8,15,2a;0x00000003)&quot;,
                    &quot;(0x0020011c,IDs:;0x00000003)&quot;,
                    &quot;(0x0020011c;0x00000003)&quot;, })
    if (std::regex_match(std::string(str), match, reg)) {
      std::cout &lt;&lt; &quot;IDHex1: &quot; &lt;&lt; match[1];
      if (match[2] != &quot;&quot;) std::cout &lt;&lt; &quot;, ID-List: &quot; &lt;&lt; match[2];
      std::cout &lt;&lt; &quot;, IDHex2: &quot; &lt;&lt; match[3] &lt;&lt; '\n';
    }
}
</code></pre>
<p>Ausgabe:</p>
<pre><code>IDHex1: 0x0020011c, ID-List: 2,3,4,8,15,2a, IDHex2: 0x00000003
IDHex1: 0x0020011c, IDHex2: 0x00000003
IDHex1: 0x0020011c, IDHex2: 0x00000003
</code></pre>
<p>Habe den Regex mal Case insensitive gemacht, damit ich weniger schreiben muss und er etwas performanter ist. (Er matcht dann auch ids statt IDs.)</p>
<p>Mit ?: kann man unbenannte Gruppen machen, dann reduziert den Overhead wieder etwas und match ist schön aufgeräumt. Dann noch \d statt 0-9 weil das ein Zeiche einspart.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2410867</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2410867</guid><dc:creator><![CDATA[unregex]]></dc:creator><pubDate>Mon, 28 Jul 2014 16:09:44 GMT</pubDate></item><item><title><![CDATA[Reply to Suche regulären ausdruck für Id Liste on Mon, 28 Jul 2014 16:17:23 GMT]]></title><description><![CDATA[<p>Wenn du den Regex nur benutzen willst um den String zu splitten (und ihn dann nachträglich selber validierst) kannst du auch</p>
<pre><code class="language-cpp">R&quot;(\((\w+)(?:,IDs:([\w,]*));(\w+)\))&quot;
</code></pre>
<p>verwenden.</p>
<p>Mit Leerzeichen kommt der auch nicht zurecht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2410868</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2410868</guid><dc:creator><![CDATA[unregex]]></dc:creator><pubDate>Mon, 28 Jul 2014 16:17:23 GMT</pubDate></item><item><title><![CDATA[Reply to Suche regulären ausdruck für Id Liste on Mon, 28 Jul 2014 19:49:40 GMT]]></title><description><![CDATA[<p>Die Antworten sind schon sehr hilfreich. Vielen Dank euch allen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2410907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2410907</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Mon, 28 Jul 2014 19:49:40 GMT</pubDate></item></channel></rss>