<?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 return nothing with QRegularExpression]]></title><description><![CDATA[<p dir="auto"><em>hi everyone,</em></p>
<p dir="auto">I have created a desktop application with QT 5.13.2 and MSVC 2017 32 bit<br />
It's an electronic stock manager with mongoDB in background</p>
<p dir="auto">I'm doing the search engine for my app.<br />
I've a search Field, where i can use some basic syntax.</p>
<p dir="auto"><strong>eg:</strong></p>
<p dir="auto"><strong>Search with value only:</strong></p>
<ul>
<li>value</li>
<li>value,value,value;</li>
<li>value|value|value;</li>
</ul>
<p dir="auto"><strong>Search with referenced value</strong></p>
<ul>
<li>ref=value</li>
<li>ref=value&amp;ref=value&amp;ref=value;</li>
<li>ref=value|ref=value|ref=value;</li>
</ul>
<p dir="auto">First i planned to implement a parser, but i thinks it's a bit oversized for this purpose. So i'm gonna using regex, but i never doing that before.</p>
<p dir="auto">I have doing on <a href="http://regex101.com" target="_blank" rel="noopener noreferrer nofollow ugc">regex101.com</a> my regex that seem do be fonctional on the site, but when i run it with QRegularExpression they don't return the same thing.</p>
<p dir="auto">They are in PCRE .</p>
<pre><code>reference value = ([\w]{1,}[\s]{0,})([\=|\&lt;|\&gt;])([\s]{0,}[\w]{1,})([\s]{0,}[\&amp;|\||\&lt;|\&gt;\;])
value only = ([\w]{1,}[\,\h\;\|\|]{1})
</code></pre>
<p dir="auto">actually for the two regex, if i input :<br />
value<br />
OR<br />
ref=value<br />
I need to add an semi colon a the end of text. how i could rig of that ?</p>
<p dir="auto">And if the string is :<br />
element=value&amp;element=value&amp;element=value;</p>
<p dir="auto">and in debugger, i watch the QStringList the only thing that comes in is: "element"</p>
<p dir="auto">could you please help me for this regex problem ?</p>
<p dir="auto">My c++ code is: (I'm testing only referenced value here)</p>
<pre><code>   const QString regexByRef = "([\\w]{1,}[\\s]{0,})([\\=|\\&lt;|\\&gt;])([\\s]{0,}[\\w]{1,})([\\s]{0,}[\\&amp;|\\||\\&lt;|\\&gt;\\;])";
   const QString regexByValue = "([\\w]{1,}[\\,\\h\\;\\|\\&amp;]{1})";
   QRegularExpression re(regexByRef,QRegularExpression::CaseInsensitiveOption);
   re.setPatternOptions(QRegularExpression::MultilineOption);
   if(re.isValid())
   {
       QRegularExpressionMatchIterator it = re.globalMatch(input);
       QStringList words;
       while (it.hasNext()) {
           QRegularExpressionMatch match = it.next();
           QString word = match.captured(1);
           words &lt;&lt; word;
       }

   }
</code></pre>
]]></description><link>https://forum.qt.io/topic/110417/regex-return-nothing-with-qregularexpression</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 16:49:19 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/110417.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 07 Jan 2020 10:24:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regex return nothing with QRegularExpression on Mon, 13 Jan 2020 22:14:26 GMT]]></title><description><![CDATA[<p dir="auto">thanks for your help, it's very appreciate</p>
]]></description><link>https://forum.qt.io/post/572198</link><guid isPermaLink="true">https://forum.qt.io/post/572198</guid><dc:creator><![CDATA[Drdgekil]]></dc:creator><pubDate>Mon, 13 Jan 2020 22:14:26 GMT</pubDate></item><item><title><![CDATA[Reply to Regex return nothing with QRegularExpression on Sun, 12 Jan 2020 19:22:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/drdgekil">@<bdi>Drdgekil</bdi></a> said in <a href="/post/571797">Regex return nothing with QRegularExpression</a>:</p>
<blockquote>
<p dir="auto">what is the utility of the R"***   ?</p>
</blockquote>
<p dir="auto">It's a raw string literal, it allows you not to care about escaping characters in the string</p>
]]></description><link>https://forum.qt.io/post/571998</link><guid isPermaLink="true">https://forum.qt.io/post/571998</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Sun, 12 Jan 2020 19:22:42 GMT</pubDate></item><item><title><![CDATA[Reply to Regex return nothing with QRegularExpression on Fri, 10 Jan 2020 22:19:52 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
thanks it's working like a charm.</p>
<p dir="auto">what is the utility of the R"***   ?</p>
]]></description><link>https://forum.qt.io/post/571797</link><guid isPermaLink="true">https://forum.qt.io/post/571797</guid><dc:creator><![CDATA[Drdgekil]]></dc:creator><pubDate>Fri, 10 Jan 2020 22:19:52 GMT</pubDate></item><item><title><![CDATA[Reply to Regex return nothing with QRegularExpression on Wed, 08 Jan 2020 12:26:46 GMT]]></title><description><![CDATA[<p dir="auto">ok, this is tested and should be working:</p>
<pre><code class="language-cpp">#include &lt;QRegularExpression&gt;
#include &lt;QDebug&gt;
int main(int argc, char *argv[])
{
    const QString inputs[] = {
        QStringLiteral("value")
        ,QStringLiteral("value,value,value;")
        ,QStringLiteral("value|value|value;")
        ,QStringLiteral("ref=value")
        ,QStringLiteral("ref=value&amp;ref=value&amp;ref=value;")
        ,QStringLiteral("ref=value|ref=value|ref=value;")
        ,QStringLiteral("element=value&amp;element=value&amp;element=value;")
    };
    const QRegularExpression re(QStringLiteral(R"***(([\&amp;\|\&lt;\&gt;\h,]?)(\w+)\s*(?:=\s*(\w+)\s*\;?)?)***"));
    for(const QString&amp; input : inputs){
        qDebug() &lt;&lt; "Input: " &lt;&lt; input;
        QRegularExpressionMatchIterator it = re.globalMatch(input);
        while (it.hasNext()) {
            const QRegularExpressionMatch match = it.next();
            switch(match.lastCapturedIndex()){
            case 2:
                qDebug() &lt;&lt; "Value Only";
                if(!match.capturedRef(1).isEmpty())
                    qDebug() &lt;&lt; "Previous separator: " &lt;&lt;  match.capturedRef(1);
                qDebug() &lt;&lt; "Value: " &lt;&lt;  match.capturedRef(2);
                break;
            case 3:
                qDebug() &lt;&lt; "Referenced Value";
                if(!match.capturedRef(1).isEmpty())
                    qDebug() &lt;&lt; "Previous separator: " &lt;&lt;  match.capturedRef(1);
                qDebug() &lt;&lt; "Value: " &lt;&lt;  match.capturedRef(2) &lt;&lt; "=" &lt;&lt; match.capturedRef(3);
                break;
            default:
                Q_UNREACHABLE();
                break;
            }
        }
    }
    return 0;
}
</code></pre>
]]></description><link>https://forum.qt.io/post/571202</link><guid isPermaLink="true">https://forum.qt.io/post/571202</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Wed, 08 Jan 2020 12:26:46 GMT</pubDate></item><item><title><![CDATA[Reply to Regex return nothing with QRegularExpression on Wed, 08 Jan 2020 11:29:16 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/vronin">@<bdi>VRonin</bdi></a><br />
Thanks for your response,</p>
<p dir="auto">i've tried your code.<br />
if i input:</p>
<pre><code>element=value&amp;element=value&amp;element=value;
</code></pre>
<p dir="auto">it returns me :</p>
<pre><code>element 
value
</code></pre>
<p dir="auto">but i need the separator everytime, plus it gave me only the first occurence of</p>
<pre><code>element=value
</code></pre>
<p dir="auto">after that it raise the exception Q_UNREACHABLE</p>
]]></description><link>https://forum.qt.io/post/571190</link><guid isPermaLink="true">https://forum.qt.io/post/571190</guid><dc:creator><![CDATA[Drdgekil]]></dc:creator><pubDate>Wed, 08 Jan 2020 11:29:16 GMT</pubDate></item><item><title><![CDATA[Reply to Regex return nothing with QRegularExpression on Tue, 07 Jan 2020 13:11:01 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">const QRegularExpression re(QStringLiteral(R"***((?:[\,\;\h\|]?(\w+))|(?:([\&amp;\|\&lt;\&gt;]?)(\w+)\s*=\s*(\w+)\s*\;?))***"));
QRegularExpressionMatchIterator it = re.globalMatch(input);
while (it.hasNext()) {
const QRegularExpressionMatch match = it.next();
switch(match.lastCapturedIndex()){
case 1: //value only
qDebug() &lt;&lt; "Captured Value: " &lt;&lt; match.capturedRef(1);
break;
case 2: // first referenced value
qDebug() &lt;&lt; match.capturedRef(1) &lt;&lt; "=" &lt;&lt; match.capturedRef(2);
break;
case 3: //subsequent referenced value
qDebug() &lt;&lt; "Separator: " &lt;&lt; match.capturedRef(1);
qDebug() &lt;&lt; match.capturedRef(2) &lt;&lt; "=" &lt;&lt; match.capturedRef(3);
break;
default:
Q_UNREACHABLE();
break;
}
}
</code></pre>
]]></description><link>https://forum.qt.io/post/570963</link><guid isPermaLink="true">https://forum.qt.io/post/570963</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Tue, 07 Jan 2020 13:11:01 GMT</pubDate></item></channel></rss>