<?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[RegexReplace]]></title><description><![CDATA[<pre><code>QString QRegexReplace(coQString str, const QString&amp; regex
    , const QString&amp; replace, QRegularExpression::PatternOption flag)
{
    QRegularExpression re(regex, flag);
    return str.replace(re, replace);
}

QString s = "111111111111111111111111111111111111111110";
 s = QRegexReplace(s, ".{6}", "|$0");
</code></pre>
<p dir="auto">My function is replacing <code>s</code> to <code>|$0|$0|$0|$0|$0|$0|$0</code></p>
<p dir="auto">How i could get the same result as seen on: <a href="https://regex101.com/r/bsgCKf/1" target="_blank" rel="noopener noreferrer nofollow ugc">https://regex101.com/r/bsgCKf/1</a><br />
Im trying to get <code>s</code> to <code>|111111|111111|111111|111111|111111|111111|111110</code></p>
]]></description><link>https://forum.qt.io/topic/139173/regexreplace</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 12:34:06 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139173.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 Sep 2022 18:51:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to RegexReplace on Fri, 09 Sep 2022 07:52:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/derreisende">@<bdi>DerReisende</bdi></a><br />
The problem is that is apparently/evidently not true, or not sufficiently accurate!</p>
<p dir="auto">On the regex site they offer "flavor" of <strong>PCRE2 (PHP &gt;= 7.3)</strong> and their "Help" for that states "Perl	PCRE2".  And if you use <code>|$0</code> for <strong>Substitution</strong> that gives the OP's desired result of <code>|111111|111111|111111|111111|111111|111111|111110</code>.  You can see this from the link the OP supplied: <a href="https://regex101.com/r/bsgCKf/1" target="_blank" rel="noopener noreferrer nofollow ugc">https://regex101.com/r/bsgCKf/1</a></p>
<p dir="auto">That would be fine if OP then reported using that in Qt as <code>QRegexReplace(s, ".{6}", "|$0");</code> delivered same.  The problem is it does <strong>not</strong>!  He says that gives him <code>|$0|$0|$0|$0|$0|$0|$0</code>, i.e. <code>$0</code> is not being recognised/substituted.  That can be seen if e.g. you change "flavor" over to <strong>Python</strong>, which does not recognise <code>$0</code>.</p>
<p dir="auto">I found that did work in various "flavors" with parentheses-capture and <code>\1</code>, see my <a href="https://regex101.com/r/YOrWq9/1" target="_blank" rel="noopener noreferrer nofollow ugc">https://regex101.com/r/YOrWq9/1</a>, hence my suggestion OP try <code>QRegexReplace(s, "(.{6})", "|\\1");</code> in Qt, which he confirms "This does work"....</p>
]]></description><link>https://forum.qt.io/post/728025</link><guid isPermaLink="true">https://forum.qt.io/post/728025</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 09 Sep 2022 07:52:34 GMT</pubDate></item><item><title><![CDATA[Reply to RegexReplace on Fri, 09 Sep 2022 07:40:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
From the Qt5/Qt6 doc:<br />
„QRegularExpression implements Perl-compatible regular expressions.“</p>
]]></description><link>https://forum.qt.io/post/728024</link><guid isPermaLink="true">https://forum.qt.io/post/728024</guid><dc:creator><![CDATA[DerReisende]]></dc:creator><pubDate>Fri, 09 Sep 2022 07:40:27 GMT</pubDate></item><item><title><![CDATA[Reply to RegexReplace on Thu, 08 Sep 2022 22:57:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/cesar">@<bdi>Cesar</bdi></a><br />
I don't know, your way is not supported by the regular expressions used in Qt is all I can say.  The one I gave you works in <strong>PCRE (PHP &lt; 7.3)</strong>, maybe that is what Qt uses.</p>
]]></description><link>https://forum.qt.io/post/727977</link><guid isPermaLink="true">https://forum.qt.io/post/727977</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 08 Sep 2022 22:57:51 GMT</pubDate></item><item><title><![CDATA[Reply to RegexReplace on Thu, 08 Sep 2022 22:49:46 GMT]]></title><description><![CDATA[<p dir="auto">This does work, but i would like to understand why mregex isn't working?</p>
]]></description><link>https://forum.qt.io/post/727976</link><guid isPermaLink="true">https://forum.qt.io/post/727976</guid><dc:creator><![CDATA[Cesar]]></dc:creator><pubDate>Thu, 08 Sep 2022 22:49:46 GMT</pubDate></item><item><title><![CDATA[Reply to RegexReplace on Thu, 08 Sep 2022 19:12:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/cesar">@<bdi>Cesar</bdi></a><br />
Good question!  I cannot test for Qt, but try</p>
<pre><code>s = QRegexReplace(s, "(.{6})", "|\\1");
</code></pre>
<p dir="auto">?</p>
<p dir="auto"><a href="https://regex101.com/r/YOrWq9/1" target="_blank" rel="noopener noreferrer nofollow ugc">https://regex101.com/r/YOrWq9/1</a></p>
]]></description><link>https://forum.qt.io/post/727959</link><guid isPermaLink="true">https://forum.qt.io/post/727959</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 08 Sep 2022 19:12:13 GMT</pubDate></item></channel></rss>