<?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 for deleting a number in a line only if it is the only one]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">I’m looking for a regex that will find a number in a line which contains no other number - namely only “1.” if there is no “2.”, “3.”, and so on, in the same line.</p>
<p dir="auto">Example:<br />
entry1 [tab] 1.  definition 2. another definition 3. another one<br />
entry2 [tab] 1.  definition<br />
entry3 [tab] 1.  definition 2. another definition 3. another one 4. another one</p>
<p dir="auto">It should find only the “1.” in the second line above, the one with entry2. This  number (“1.”) may or may not follow a tab character [e.g. “ethyl alcohol tab Chem. 1.” ] and may or may not be followed by only one space.</p>
<p dir="auto">Mant thanks in advance!<br />
glossar</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/20432/regex-for-deleting-a-number-in-a-line-only-if-it-is-the-only-one</link><generator>RSS for Node</generator><lastBuildDate>Sun, 13 Sep 2026 11:12:59 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/20432.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 06 Dec 2020 08:53:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regex for deleting a number in a line only if it is the only one on Sun, 06 Dec 2020 20:55:07 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> and <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: Terry-R">@<bdi>Terry-R</bdi></a> ,</p>
<p dir="auto">Thank you both for your subsequent solutions. Alan’s <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a>  formula have done the job, so I can’t even reproduce the problem now :P, but I’ll note yours just in case I need it again.</p>
<p dir="auto">Thanks again.<br />
glossar</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60507</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60507</guid><dc:creator><![CDATA[glossar]]></dc:creator><pubDate>Sun, 06 Dec 2020 20:55:07 GMT</pubDate></item><item><title><![CDATA[Reply to Regex for deleting a number in a line only if it is the only one on Sun, 06 Dec 2020 19:51:04 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/glossar" aria-label="Profile: glossar">@<bdi>glossar</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: alan-kilborn">@<bdi>alan-kilborn</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a>, and <strong>All</strong>,</p>
<p dir="auto">Here are my <strong>solutions</strong> :</p>
<ul>
<li>The <strong>first</strong> regex is similar to <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: alan-kilborn">@<bdi>alan-kilborn</bdi></a>’s one :</li>
</ul>
<pre><code class="language-z">SEARCH    (?x-s)  ^.*?  \K   \d+\.\x20  ( .+  \d+\.  (*SKIP)(*F) | )

REPLACE   Leave EMPTY
</code></pre>
<ul>
<li>The <strong>second</strong> one does <strong>not</strong> use <strong><code>backtracking control verbs</code></strong> but ensures that <strong>some</strong> zones of text do <strong>not</strong> contain any <strong>digit</strong> :</li>
</ul>
<pre><code class="language-z">(?x)  ^entry\d+  ( [^\d\r\n]+ )  \K   \d+\.\x20  (?=(?1)$)
</code></pre>
<p dir="auto">Best regards</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60505</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60505</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 06 Dec 2020 19:51:04 GMT</pubDate></item><item><title><![CDATA[Reply to Regex for deleting a number in a line only if it is the only one on Sun, 06 Dec 2020 18:59:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/glossar" aria-label="Profile: glossar">@<bdi>glossar</bdi></a> said in <a href="/post/60493">Regex for deleting a number in a line only if it is the only one</a>:</p>
<blockquote>
<p dir="auto">It should find only the “1.” in the second line above, the one with entry2.</p>
</blockquote>
<p dir="auto">I have this solution. Easier (on the eye) than <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a>’s solution and it seems to work as expected.</p>
<p dir="auto">Replace function<br />
Find What:<code>1\.\h(?!.+?2\.)</code><br />
Replace With:    empty field here</p>
<p dir="auto">So it says look for a <code>1.</code> and the rest of the line cannot contain a <code>2.</code>. So it assumes with a multi definition line the numbers will ascend gracefully, i.e. 1., 2., 3., 4. etc. So any line that DOES have the <code>2.</code> will not be altered. As there is no replacement field the <code>1.</code> and a following space are removed.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60503</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60503</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Sun, 06 Dec 2020 18:59:47 GMT</pubDate></item><item><title><![CDATA[Reply to Regex for deleting a number in a line only if it is the only one on Sun, 06 Dec 2020 12:21:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a><br />
Many thanks! Much appreciated. It works like a magic!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60499</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60499</guid><dc:creator><![CDATA[glossar]]></dc:creator><pubDate>Sun, 06 Dec 2020 12:21:19 GMT</pubDate></item><item><title><![CDATA[Reply to Regex for deleting a number in a line only if it is the only one on Sun, 06 Dec 2020 12:01:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/glossar" aria-label="Profile: glossar">@<bdi>glossar</bdi></a></p>
<p dir="auto">Well, this seems to work, but it may be “overcomplicated”:</p>
<p dir="auto">find: <code>(?-s)^.*?\K\d+\. (?:(?:.*?\d+\.(*SKIP)(*F))|(?:(?!.*?\d+\.)))</code><br />
repl: nothing<br />
action: Replace All</p>
<p dir="auto">It will turn this text:</p>
<pre><code>entry1 [tab] 1. definition 2. another definition 3. another one
entry2 [tab] 1. definition
entry3 [tab] 1. definition 2. another definition 3. another one 4. another one
</code></pre>
<p dir="auto">into this text:</p>
<pre><code>entry1 [tab] 1. definition 2. another definition 3. another one
entry2 [tab] definition
entry3 [tab] 1. definition 2. another definition 3. another one 4. another one
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/60498</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60498</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Sun, 06 Dec 2020 12:01:55 GMT</pubDate></item><item><title><![CDATA[Reply to Regex for deleting a number in a line only if it is the only one on Sun, 06 Dec 2020 10:42:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/glossar" aria-label="Profile: glossar">@<bdi>glossar</bdi></a> said in <a href="/post/60496">Regex for deleting a number in a line only if it is the only one</a>:</p>
<blockquote>
<p dir="auto">I assume I can’t put back those lines, cut with the Bookmarks function, in the same place.</p>
</blockquote>
<p dir="auto">It is possible but takes a lot more steps. It involves adding line numbers at start of line, then removing them later.</p>
<p dir="auto">Someone should be able to conjure up a regex for you. I would if I were at a PC. Currently late in evening so it will have to be someone else.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60497</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60497</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Sun, 06 Dec 2020 10:42:54 GMT</pubDate></item><item><title><![CDATA[Reply to Regex for deleting a number in a line only if it is the only one on Sun, 06 Dec 2020 10:14:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: Terry-R">@<bdi>Terry-R</bdi></a> said in <a href="/post/60495">Regex for deleting a number in a line only if it is the only one</a>:</p>
<blockquote>
<p dir="auto">If just the number then you could cut those non bookmarked lines elsewhere and then remove using a simple regex. Then move back, although they will be out of original order.</p>
<p dir="auto">Terry</p>
</blockquote>
<p dir="auto">Hi Terry,<br />
Thanks for the effort.<br />
I’m tidying up the entries, putting things in order, and deleting junks (in this case the number “1.” since it is useless/unnecessary to number a single item (definition)). I’ve not compeleted the task yet, so the order of the entries is currently important. I assume I can’t put back those lines, cut with the Bookmarks function, in the same place. It would hence be nice if this is performed in place (in the same line) with a regex or any other function of Notepad++ itself.</p>
<p dir="auto">After the operation, the result should look like this:</p>
<p dir="auto">entry2 [tab] definition</p>
<p dir="auto">Thanks,<br />
glossar</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60496</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60496</guid><dc:creator><![CDATA[glossar]]></dc:creator><pubDate>Sun, 06 Dec 2020 10:14:49 GMT</pubDate></item><item><title><![CDATA[Reply to Regex for deleting a number in a line only if it is the only one on Sun, 06 Dec 2020 09:17:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: Terry-R">@<bdi>Terry-R</bdi></a> said in <a href="/post/60494">Regex for deleting a number in a line only if it is the only one</a>:</p>
<blockquote>
<p dir="auto">Then look for “remove all non bookmarked lines” (under bookmark? sorry not on PC right now).</p>
</blockquote>
<p dir="auto">Sorry I may have misread your question. Do you want to remove the line, which is my solution or JUST the <code>1.</code> in that line. If just the number then you could cut those non bookmarked lines elsewhere and then remove using a simple regex. Then move back, although they will be out of original order.</p>
<p dir="auto">Sometimes a simple multi-part solution is easier, especially when the user needs to understand the process and support it going forward.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60495</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60495</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Sun, 06 Dec 2020 09:17:38 GMT</pubDate></item><item><title><![CDATA[Reply to Regex for deleting a number in a line only if it is the only one on Sun, 06 Dec 2020 09:10:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/glossar" aria-label="Profile: glossar">@<bdi>glossar</bdi></a> said in <a href="/post/60493">Regex for deleting a number in a line only if it is the only one</a>:</p>
<blockquote>
<p dir="auto">if there is no “2.”, “3.”, and so on, in the same line.</p>
</blockquote>
<p dir="auto">I don’t think it even needs a regex. If every line which contains multiple definitions includes a <code>2,</code> at a minimum then use the “Mark” function and also tick bookmark lines. The search mode can be normal and type in <code>2,</code>. Click on Mark All. Then look for “remove all non bookmarked lines” (under bookmark? sorry not on PC right now).</p>
<p dir="auto">You should be left with lines that have multiple definitions only.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60494</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60494</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Sun, 06 Dec 2020 09:10:49 GMT</pubDate></item></channel></rss>