<?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 capture date if it exists in a block but match the block anyway]]></title><description><![CDATA[<p dir="auto">I am using this regex expression</p>
<pre><code>(^(@X\d.+F\.$\R)(?s:.*?)(^\d\d \D\D\D \d\d\d\d\.)?(?s:.*?)(?=@|==))
</code></pre>
<p dir="auto">to capture two groups and capture an optional date in a test sample block:</p>
<pre><code>== Ma ==
@X1@ F.
line 1
line 2
@X2@ F.
line 3.
line 4
02 FEB 1842.
line 6
==
</code></pre>
<p dir="auto">This matches two groups</p>
<pre><code>**@X1@ F.**
line 1
line 2
</code></pre>
<p dir="auto">and</p>
<pre><code>**@X2@ F.**
line 3.
line 4
02 FEB 1842.
line 6
</code></pre>
<p dir="auto">but does not capture the date</p>
<p dir="auto">whereas</p>
<pre><code>^(@X\d.+F\.$\R)(?s:.*?)(^\d\d \D\D\D \d\d\d\d\.)(?s:.*?)(?=@|==)
</code></pre>
<p dir="auto">matches just one group (but both of the required groups)</p>
<pre><code>**@X1@ F.**
line 1
line 2
@X2@ F.
line 3.
line 4
**02 FEB 1842.**
line 6
</code></pre>
<p dir="auto">and captures the date.</p>
<p dir="auto">Can someone (<a href="https://community.notepad-plus-plus.org/user/guy038">guy038?</a>) produce a regex that will capture the two groups AND the optional date?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/19213/regex-capture-date-if-it-exists-in-a-block-but-match-the-block-anyway</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 19:14:58 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/19213.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 13 Apr 2020 11:53:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regex capture date if it exists in a block but match the block anyway on Mon, 13 Apr 2020 17:41:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/195">@guy038</a> Thank you so much, Guy. In order to achieve what I want, I adjusted the search regex slightly, so that the whole block, the label line (^<a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/16850">@X</a>[/d]+@ F./R) and date are all captured:</p>
<pre><code>(?-s)((^@X.+\R)(?:(?s:[^@]*?)(\d\d\x20\w\w\w\x20\d\d\d\d)\.(?s:.*?)|(?s:.*?)))(?=^@X|^==|\Z)
</code></pre>
<p dir="auto">Best Regards. Stay safe!<br />
John</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52533</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52533</guid><dc:creator><![CDATA[John Slee]]></dc:creator><pubDate>Mon, 13 Apr 2020 17:41:27 GMT</pubDate></item><item><title><![CDATA[Reply to Regex capture date if it exists in a block but match the block anyway on Mon, 13 Apr 2020 15:47:44 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/18012">@john-slee</a>, <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@alan-kilborn</a> and <strong>All</strong>,</p>
<p dir="auto">I think that the following <strong>regex</strong> S/R should be <strong>OK</strong> !</p>
<p dir="auto">SEARCH <strong><code>(?-s)^@X.+\R(?:(?s:[^@]*?)(\d\d\x20\w\w\w\x20\d\d\d\d)\.(?s:.*?)|(?s:.*?))(?=^@X|^==|\Z)</code></strong></p>
<p dir="auto">If we use the <strong>in-line</strong> modifier <strong><code>(?x)</code></strong> we can build the corresponding <strong>multi-lines</strong> regex, with <strong>explanations</strong> in comments :</p>
<pre><code class="language-z">(?x)                           # FREE-SPACING mode
(?-s)                          # Forces the DOT regex symbol to match a SINGLE STANDARD character , only ( Not EOL chars )
^@X.+\R                        # An ENTIRE Line BEGINNING with @X
(?:                            # NON-capturing group, beginning 2 ALTERNATIVES
(?s:[^@]*?)                    #     SHORTEST range of chars, even NULL, DIFFERENT from @, till the DATE, in a NON-capturing group
(\d\d\x20\w\w\w\x20\d\d\d\d)\. #     DATE, stored in CAPTURING group 1, followed with a DOT
(?s:.*?)                       #     SHORTEST range of chars till the LOOK-AROUND, in a NON-capturing group
|                              #   OR
(?s:.*?)                       #     SHORTEST range of chars, even NULL, till the LOOK-AROUND, in a NON-capturing group
)                              # END of the NON-capturing group
(?=^@X|^==|\Z)                 # LOOK-AROUND ( if FOLLOWED with @X or ==, BEGINNING a line, or the END of file [ possibly PRECDEDED with EMPTY lines ] )
</code></pre>
<p dir="auto">You can select <strong>all</strong> that block, with <strong><code>Ctrl+C</code></strong> and paste it, with <strong><code>Ctrl + V</code></strong>, in the <strong>Find what</strong> zone of the <strong>Find</strong> dialog ;-))</p>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">Each matched <strong>multi</strong>-lines block, from a line <strong><code>^@X...</code></strong> to the <strong>next</strong> line <strong><code>^@X</code></strong>, <strong>excluded</strong>, can be used in <strong>replacement</strong> with the <strong><code>$0</code></strong> syntax ( The <strong>overall</strong> match )</p>
</li>
<li>
<p dir="auto">The <strong>group <code>1</code></strong> stores the <strong>date</strong>, when <strong>present</strong> in <strong>current</strong> block and is an <strong>empty</strong> string when the date is <strong>absent</strong> from block and you can re-use the date, in <strong>replacement</strong>, with the <strong><code>\1</code></strong> or <strong><code>$1</code></strong> syntaxes</p>
</li>
</ul>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52527</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52527</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Mon, 13 Apr 2020 15:47:44 GMT</pubDate></item><item><title><![CDATA[Reply to Regex capture date if it exists in a block but match the block anyway on Mon, 13 Apr 2020 14:21:06 GMT]]></title><description><![CDATA[<p dir="auto">it means it could be</p>
<pre><code>== Ma ==
@X1@ F.
line 1
line 2
@X2@ F.
line 3.
03 MAR 1806.
line 6
==
</code></pre>
<pre><code>== Ma ==
@X1@ F.
line 1
line 2
@X2@ F.
line 3.
line 4
line 6
==
</code></pre>
<p dir="auto">or</p>
<pre><code>== Ma ==
@X1@ F.
line 1
04 FEB 1811.
line 2
@X2@ F.
line 3.
03 MAR 1806.
line 6
==
</code></pre>
<p dir="auto">or</p>
<pre><code>== Ma ==
@X1@ F.
line 1
04 JUN 1961.
line 2
@X2@ F.
line 3.
line 6
==
</code></pre>
<p dir="auto">Each block begins with the @…@ F. line and can have a variable number of lines, one of which can be the date line.<br />
I want to match each block and capture the date where it occurs.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52521</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52521</guid><dc:creator><![CDATA[John Slee]]></dc:creator><pubDate>Mon, 13 Apr 2020 14:21:06 GMT</pubDate></item><item><title><![CDATA[Reply to Regex capture date if it exists in a block but match the block anyway on Mon, 13 Apr 2020 12:08:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/18012">@John-Slee</a></p>
<p dir="auto">What does “optional date” mean?</p>
<p dir="auto">Does it mean your “before” block could look like this (exactly as you show):</p>
<pre><code>== Ma ==
@X1@ F.
line 1
line 2
@X2@ F.
line 3.
line 4
02 FEB 1842.
line 6
==
</code></pre>
<p dir="auto">Or it (the “before” block) could look like this:</p>
<pre><code>== Ma ==
@X1@ F.
line 1
line 2
@X2@ F.
line 3.
line 4
line 6
==
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/52497</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52497</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 13 Apr 2020 12:08:45 GMT</pubDate></item></channel></rss>