<?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[Marked text manipulation]]></title><description><![CDATA[<p dir="auto">Is there any possibility to copy/delete marked text which is regex search result?<br />
Yes, I know I am able to bookmark lines and to remove (un)bookmarked ones, but I need to remove <strong>only the marked text</strong>, not the full line.<br />
I found the <a href="https://notepad-plus-plus.org/community/topic/10388/copy-marked-text" rel="nofollow ugc">old tread</a> with the similar question unanswered. Has situation changed since then?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/12710/marked-text-manipulation</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Jul 2026 16:14:25 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/12710.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 12 Nov 2016 11:50:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Marked text manipulation on Tue, 26 Aug 2025 22:38:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chk1" aria-label="Profile: chk1">@<bdi>chk1</bdi></a> said in <a href="/post/103042">Marked text manipulation</a>:</p>
<blockquote>
<p dir="auto">Right now, with help of the script, I open the Marks search (Ctrl+M), enter my search term and press “Mark all”. Then I run the script to convert all marks to multi-edit selections. I want to reduce these extra steps if possible, i.e. in the best case: Ctrl+F, enter search word, hit Alt+Enter.</p>
</blockquote>
<p dir="auto">It might not be worth it for your case, but the <a href="https://coises.github.io/ColumnsPlusPlus/help.htm#search" rel="nofollow ugc">Search dialog</a> in the Columns++ plugin has <strong>Select All</strong> as an option on the dropdown menu on the <strong>Count</strong> button.</p>
<p dir="auto">You can assign a shortcut to Columns++ | Search in Notepad++ shortcut mapper; but at present, there is no straightforward way to open the Count button menu using only the keyboard.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/103044</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/103044</guid><dc:creator><![CDATA[Coises]]></dc:creator><pubDate>Tue, 26 Aug 2025 22:38:40 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Tue, 26 Aug 2025 21:32:09 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> Thanks for the quick response, but the Search results window is not what I mean. When I press Alt+Enter (or an alternative key combo) I want every search result to be selected via multi-editing in the editor window, and not in a separate window or sidebar.</p>
<p dir="auto">Right now, with help of the script, I open the Marks search (Ctrl+M), enter my search term and press “Mark all”. Then I run the script to convert all marks to multi-edit selections. I want to reduce these extra steps if possible, i.e. in the best case: Ctrl+F, enter search word, hit Alt+Enter.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/103042</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/103042</guid><dc:creator><![CDATA[chk1]]></dc:creator><pubDate>Tue, 26 Aug 2025 21:32:09 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Tue, 26 Aug 2025 21:23:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chk1" aria-label="Profile: chk1">@<bdi>chk1</bdi></a> said in <a href="/post/103040">Marked text manipulation</a>:</p>
<blockquote>
<p dir="auto">I could just hit Alt+Enter in the search bar and it would immediately make all search results into cursors.</p>
</blockquote>
<p dir="auto">Do you mean make the search results into “links” to the actual text in the file? Because if so, then you should understand that already happens.</p>
<p dir="auto">The mouse cursor doesn’t indicate that they are links, but in the “Search results” window that appears, double clicking on any search result line will make the main window move lines until that search result shows.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/103041</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/103041</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Tue, 26 Aug 2025 21:23:12 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Tue, 26 Aug 2025 21:20:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dinkumoil" aria-label="Profile: dinkumoil">@<bdi>dinkumoil</bdi></a> said in <a href="/post/60152">Marked text manipulation</a>:</p>
<blockquote>
<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></p>
<p dir="auto">My preferred solution would have been to <strong>select</strong> all marked text because this provides more flexibility. This way the user could</p>
<ul>
<li>copy</li>
<li>cut</li>
<li>delete</li>
<li>change</li>
</ul>
<p dir="auto">the marked search results.</p>
<p dir="auto">To achieve that I wrote the following <em>Lua</em> script (intended to be used with, well, the <em>LuaScript</em> plugin).</p>
<pre><code>// snip
</code></pre>
<p dir="auto">After adding this code to the <em>startup.lua</em> file and restarting Notepad++, the plugin’s submenu provides a new entry <em>Select Marked</em> which can be assigned to a keyboard shortcut.</p>
</blockquote>
<p dir="auto">Thank you so much for that code, I converted it to Python for fans of the PythonScript plugin:</p>
<pre><code class="language-py"># -*- coding: utf-8 -*-
from Npp import editor

# https://community.notepad-plus-plus.org/topic/12710/marked-text-manipulation/48?_=1756239096378
SCE_UNIVERSAL_FOUND_STYLE = 31

def mark_to_multi():
    has_marked_items = False
    pos = 0
    while pos &lt; editor.getTextLength():
        if editor.indicatorValueAt(SCE_UNIVERSAL_FOUND_STYLE, pos) == 1:
            mark_start = editor.indicatorStart(SCE_UNIVERSAL_FOUND_STYLE, pos)
            mark_end   = editor.indicatorEnd(SCE_UNIVERSAL_FOUND_STYLE, pos)
            
            if editor.getSelectionEmpty() or not editor.getMultipleSelection():
                editor.setSelection(mark_end, mark_start)
            else:
                editor.addSelection(mark_end, mark_start)

            pos = mark_end
            has_marked_items = True
            editor.setIndicatorCurrent(SCE_UNIVERSAL_FOUND_STYLE)
            editor.indicatorClearRange(mark_start, mark_end-mark_start)

        pos += 1
    if has_marked_items:
        editor.scrollCaret()

mark_to_multi()
</code></pre>
<p dir="auto">The editor I used previously had a handy shortcut for this, I could just hit Alt+Enter in the search bar and it would immediately make all search results into cursors. Is there a reasonably easy way to replicate this in Notepad++? I use this function a lot.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/103040</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/103040</guid><dc:creator><![CDATA[chk1]]></dc:creator><pubDate>Tue, 26 Aug 2025 21:20:30 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Thu, 26 Nov 2020 08:14:40 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> said in <a href="/post/60154">Marked text manipulation</a>:</p>
<blockquote>
<p dir="auto">Copy and cut of selected text would jam all of the text together if it were on a selection basis (probably not really useful that way).</p>
</blockquote>
<p dir="auto">Yes, you are right. Up to now, I’ve used my script only for deleting and editing the selections. But especially being able to multi-edit all occurences of a search term or overwrite them by multi-paste vastly increases productivity.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60162</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60162</guid><dc:creator><![CDATA[dinkumoil]]></dc:creator><pubDate>Thu, 26 Nov 2020 08:14:40 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Wed, 25 Nov 2020 18:26:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dinkumoil" aria-label="Profile: dinkumoil">@<bdi>dinkumoil</bdi></a> said in <a href="/post/60152">Marked text manipulation</a>:</p>
<blockquote>
<p dir="auto">select all marked text because this provides more flexibility. This way the user could</p>
<p dir="auto">copy<br />
cut<br />
delete<br />
change</p>
</blockquote>
<p dir="auto">That’s a good idea as well, especially for delete and change (although those can be achieved, on a one-off basis, by replace-with-nothing and replace-with something ops).</p>
<p dir="auto">Copy and cut of selected text would jam all of the text together if it were on a selection basis (probably not really useful that way).</p>
<p dir="auto">I noticed this new <em>Copy Marked Text</em> command inserts a line-ending between the individual globs of marked text, which seems to make it useful, although to tell the truth I haven’t had a real application for it myself, yet.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60154</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60154</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 25 Nov 2020 18:26:09 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Wed, 25 Nov 2020 17:59: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></p>
<p dir="auto">My preferred solution would have been to <strong>select</strong> all marked text because this provides more flexibility. This way the user could</p>
<ul>
<li>copy</li>
<li>cut</li>
<li>delete</li>
<li>change</li>
</ul>
<p dir="auto">the marked search results.</p>
<p dir="auto">To achieve that I wrote the following <em>Lua</em> script (intended to be used with, well, the <em>LuaScript</em> plugin).</p>
<pre><code>-- =============================================================================
-- Add menu entry to select all items marked by find marks
-- =============================================================================

npp.AddShortcut("Select Marked", "", function()
  local indicatorIdx
  local pos, markStart, markEnd
  local hasMarkedItems

  -- Search find marks have indicator number 31
  SCE_UNIVERSAL_FOUND_STYLE = 31

  -- Remove selection but do not change cursor position
  editor.Anchor  = editor.CurrentPos
  hasMarkedItems = false

  -- Search find mark indicators and select marked text
  pos = 0
  
  while pos &lt; editor.TextLength do
    if editor:IndicatorValueAt(SCE_UNIVERSAL_FOUND_STYLE, pos) == 1 then
      markStart = editor:IndicatorStart(SCE_UNIVERSAL_FOUND_STYLE, pos)
      markEnd   = editor:IndicatorEnd(SCE_UNIVERSAL_FOUND_STYLE, pos)

      if editor.SelectionEmpty or not editor.MultipleSelection then
        editor:SetSelection(markEnd, markStart)
      else
        editor:AddSelection(markEnd, markStart)
      end

      pos            = markEnd
      hasMarkedItems = true
    end
    
    pos = pos + 1
  end

  -- Scroll last selected element into view. This is only because
  -- Npp/Scintilla will do that anyway when moving the cursor next time
  if hasMarkedItems then
    editor:ScrollCaret()
  end
end)
</code></pre>
<p dir="auto">After adding this code to the <em>startup.lua</em> file and restarting Notepad++, the plugin’s submenu provides a new entry <em>Select Marked</em> which can be assigned to a keyboard shortcut.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60152</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60152</guid><dc:creator><![CDATA[dinkumoil]]></dc:creator><pubDate>Wed, 25 Nov 2020 17:59:19 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Wed, 25 Nov 2020 13:38:51 GMT]]></title><description><![CDATA[<p dir="auto">At the time of the earlier discussions, there was no way to copy marked text natively in Notepad++, meaning without resorting to scripting. Now (7.9.1-ish) there is:</p>
<p dir="auto"><img src="/assets/uploads/files/1606311402296-77ec89fb-3ad9-4602-b8ee-4d574195eebe-image.png" alt="77ec89fb-3ad9-4602-b8ee-4d574195eebe-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Just press the indicated button after you already have marked some text.</p>
<p dir="auto">Note: I have added similar information in this somewhat-related other <a href="https://community.notepad-plus-plus.org/topic/20343/find-and-remove-everything-else">THREAD</a>.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60146</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60146</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 25 Nov 2020 13:38:51 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Wed, 16 Sep 2020 22:50:42 GMT]]></title><description><![CDATA[<p dir="auto">This may be the issue to which I was referring:  <a href="https://github.com/notepad-plus-plus/notepad-plus-plus/issues/6095" rel="nofollow ugc">https://github.com/notepad-plus-plus/notepad-plus-plus/issues/6095</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/57656</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/57656</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 16 Sep 2020 22:50:42 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Wed, 16 Sep 2020 22:32:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/laura-lucas-alday" aria-label="Profile: Laura-Lucas-Alday">@<bdi>Laura-Lucas-Alday</bdi></a></p>
<p dir="auto">Peter maybe only made it 99.9999% clear.  Perhaps the newbie 0.0001% might still be left wondering…</p>
<p dir="auto">Peter’s step 4 would be how you actually <em>run</em> the script.</p>
<p dir="auto">Be advised that in this particular case, you need to have some red-marked text for the script to operate on (hopefully this part is clear).</p>
<p dir="auto">I think there is an open issue that would make this script’s functionality a native part of Notepad++.  I will try to find it…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/57655</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/57655</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 16 Sep 2020 22:32:18 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Wed, 16 Sep 2020 21:59:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/laura-lucas-alday" aria-label="Profile: Laura-Lucas-Alday">@<bdi>Laura-Lucas-Alday</bdi></a></p>
<ol>
<li>Install PythonScript using <strong>Plugins &gt; Plugins Admin</strong></li>
<li><strong>Plugins &gt; Python Script &gt; New Script</strong></li>
<li>Paste the contents and save under <code>someName</code> (whatever name you want)</li>
<li><strong>Plugins &gt; Python Script &gt; Scripts &gt; <code>someName</code></strong></li>
<li>To add a keyboard shortcut for the script:</li>
<li><strong>Plugins &gt; Python Script &gt; Configuration</strong>,</li>
<li>select the <code>someName</code> script and <strong>Add</strong> to the menu</li>
<li>Restart Notepad++</li>
<li><code>someName</code> will now be in the main <strong>Plugins &gt; Python Script</strong> menu, not just in the <strong>Scripts</strong> submenu</li>
<li><strong>Settings &gt; Shortcut Mapper &gt; Plugin Commands</strong> will see the script, and you can assign a keyboard shortcut</li>
</ol>
]]></description><link>https://community.notepad-plus-plus.org/post/57653</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/57653</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 16 Sep 2020 21:59:09 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Wed, 16 Sep 2020 21:23:07 GMT]]></title><description><![CDATA[<p dir="auto">Can anyone explain quickly how to use the python script? As in which steps I need to do in Notepad++ to run the script.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/57651</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/57651</guid><dc:creator><![CDATA[Laura Lucas Alday]]></dc:creator><pubDate>Wed, 16 Sep 2020 21:23:07 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Sun, 03 May 2020 18:17:51 GMT]]></title><description><![CDATA[<p dir="auto">Semi-related info:</p>
<p dir="auto">Part of this current thread is about how to copy text that one has marked via <em>Mark</em>ing that requires use of a PythonScript.</p>
<p dir="auto">In a <a href="https://community.notepad-plus-plus.org/post/53394">POST</a> in another thread, I provide a script that will <em>select</em> text given conditions specified by user input.  That selected text can then be copied.</p>
<p dir="auto">Similar results thru some different methods; enough to warrant a cross-link, I guess.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/53428</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/53428</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Sun, 03 May 2020 18:17:51 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Thu, 09 Apr 2020 20:46:08 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: alan-kilborn">@<bdi>alan-kilborn</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">So, as the <strong>result</strong> of our discussion :</p>
<p dir="auto">This <strong>old</strong> post    <a href="https://community.notepad-plus-plus.org/topic/12710/marked-text-manipulation/8">https://community.notepad-plus-plus.org/topic/12710/marked-text-manipulation/8</a></p>
<p dir="auto">have been <strong>updated</strong>    <a href="https://community.notepad-plus-plus.org/topic/19189/need-a-copy-marked-lines-feature/7">https://community.notepad-plus-plus.org/topic/19189/need-a-copy-marked-lines-feature/7</a></p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/52352</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/52352</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 09 Apr 2020 20:46:08 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Fri, 27 Mar 2020 12:35:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a></p>
<p dir="auto">Thank you for the further analysis.</p>
<blockquote>
<p dir="auto">I’m really sorry, because it’s just my fault and you wouldn’t have had to look for an alternative solution</p>
</blockquote>
<p dir="auto">No worries at all! :-)</p>
<blockquote>
<p dir="auto">I don’t understand, Alan why you got a match (of only) “Alice”.  I personally only get the forename “Bob”</p>
</blockquote>
<p dir="auto">Indeed!  I guess “something happened” because if I re-run it now the same way I for sure get “Bob” as well!  Sorry for that confusion.</p>
<p dir="auto">Other comments:</p>
<p dir="auto">I did not realize (obviously) that it was merely a case of a problem with the <code>^</code> in the original expression.  :-(<br />
I totally jumped in to an almost wholly different solution, based upon something related I was working on.</p>
<blockquote>
<p dir="auto">The lesson of that story is…</p>
</blockquote>
<p dir="auto">Nice to know!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/51782</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/51782</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 27 Mar 2020 12:35:58 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Fri, 27 Mar 2020 10:43:11 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: alan-kilborn">@<bdi>alan-kilborn</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">I’m really <strong>sorry</strong>, because it’s just my <strong>fault</strong> and you wouldn’t have had to look for an <strong>alternative</strong> solution :-( Indeed, the <strong>regex</strong> S/R, that I gave in my post, below, does contains an <strong>error</strong> which is <strong>not</strong> important when using the Notepad++ <strong>Replace</strong> dialog, but which seems <strong>critical</strong> when you run a <strong>Python</strong> script, involving regexes !</p>
<p dir="auto"><a href="https://community.notepad-plus-plus.org/topic/12710/marked-text-manipulation/8">https://community.notepad-plus-plus.org/topic/12710/marked-text-manipulation/8</a></p>
<p dir="auto">I suppose that this fact should be <strong>related</strong> to this “small” point, located at the <strong>end</strong> of the description of the <strong><code>editor.rereplace</code></strong> <strong>helper method</strong> :</p>
<p dir="auto"><a href="http://npppythonscript.sourceforge.net/docs/latest/scintilla.html?highlight=editor.rereplace#Editor.rereplace" rel="nofollow ugc">http://npppythonscript.sourceforge.net/docs/latest/scintilla.html?highlight=editor.rereplace#Editor.rereplace</a></p>
<blockquote>
<p dir="auto">An small point to note, is that the replacements are first searched, and then all replacements are made. This is done for performance and reliability reasons. Generally this will have no side effects, however there may be cases where it makes a difference. (Author’s note: If you have such a case, please post a note on the forums such that it can be added to the documentation, or corrected).</p>
</blockquote>
<hr />
<p dir="auto">To understand the problem , let’s just use the <strong>beginning</strong> of your example text, pasted in a <strong>new</strong> N++ tab</p>
<pre><code class="language-diff">Alice Carol Alan Bob Ted
Ted Bob
Bob Carol Ted
Ted Carol
Alice Carol
Alice Bob
</code></pre>
<p dir="auto">If my <strong>generic</strong> regex S/R, below, with your regex <strong>choice</strong> <strong><code>(Bob|Ted)</code></strong> is used, against this text :</p>
<p dir="auto">SEARCH <strong><code>(?s)^.*?(Bob|Ted)|(?s).*\z</code></strong></p>
<p dir="auto">REPLACE <strong><code>?1\1\r\n</code></strong></p>
<p dir="auto">We get, after a click on the <strong><code> Replace All</code></strong> button or <strong>several</strong> clicks on the <strong><code>Replace</code></strong> button, and with the <strong><code>Wrap around</code></strong> option <strong>ticked</strong>, the following <strong>correct</strong> result :</p>
<pre><code class="language-diff">Bob
Ted
Ted
Bob
Bob
Ted
Ted
Bob
</code></pre>
<p dir="auto">Note that I use the <strong><code>^</code></strong> <strong>assertion</strong> which forces the regex <strong>engine</strong> to search a range of chars <strong>beginning</strong> a line. Of course, in case of <strong>replacement</strong>, no <strong>trouble</strong> at all ! Indeed, due to the <strong><code>\r\n</code></strong> syntax, any <strong>match</strong> <strong><code>\1</code></strong> is rewritten with a <strong>line-break</strong>. So, the next search, with the <strong><code>(?s)</code></strong> mode, automatically matches <strong>right after</strong> that <strong>line-break</strong>, added by the replacement !</p>
<p dir="auto">Now, let’s get back the <strong>initial</strong> text ( with <strong><code>Ctrl + Z</code></strong> ) and let’s suppose that we just want to trace the <strong>different</strong> matches of that <strong>regex</strong> S/R, using the <strong><code>Find Next</code></strong> button only. In that case, we get only <strong><code>2</code></strong> matches !!??</p>
<ul>
<li>Obviously, the <strong>first</strong> match is :</li>
</ul>
<pre><code class="language-z">Alice Carol Alan Bob
</code></pre>
<p dir="auto">But the <strong>second</strong> and final match is :</p>
<pre><code class="language-z"> Ted
Ted Bob
Bob Carol Ted
Ted Carol
Alice Carol
Alice Bob
</code></pre>
<p dir="auto">Why ? Well, after the <strong>first</strong> match, the <strong>caret</strong> location is <strong>right after</strong> the word <strong>Bob</strong> of the <strong>first</strong> line. So, it <strong>cannot</strong> match the string <strong>space</strong> + <strong>Ted</strong> because this string should <strong>begin</strong> the current line, due to, <strong>both</strong>, the <strong><code>^</code></strong> symbol and the <strong>grouping</strong> parentheses</p>
<p dir="auto">As the <strong>first</strong> alternative <strong><code>(?s)^.*?(Bob|Ted)</code></strong> <strong>cannot</strong> match, at this location, the regex engine tries the <strong>other</strong> alternative <strong><code>(?s).*\z</code></strong>, which, of course, matches <strong>all</strong> the <strong>remaining</strong> characters of <strong>current</strong> file, beginning with <strong>space</strong> + <strong>Ted</strong> of the <strong>1st</strong> line !!</p>
<p dir="auto">BTW, I don’t understand, <strong>Alan</strong> why you got a match <strong><code>Alice</code></strong>. Indeed, when running :</p>
<pre><code class="language-py">editor.rereplace(r'(?s)^.*?(Bob|Ted)|(?s).*\z', r'?1\1\r\n')
</code></pre>
<p dir="auto">I personally <strong>only</strong> get the forename <strong>Bob</strong>, which is the <strong>first</strong> word <strong>matched</strong> of the text !</p>
<hr />
<p dir="auto">Now, it’s <strong>easy</strong> to imagine the <strong>correct</strong> regex S/R to use : it should <strong>not</strong> contain any <strong><code>^</code></strong> <strong>assertion</strong> and be as below :</p>
<p dir="auto">SEARCH <strong><code>(?s).*?(Bob|Ted)|(?s).*\z</code></strong></p>
<p dir="auto">REPLACE <strong><code>?1\1\r\n</code></strong> ( or <strong><code>?1\1\n</code></strong> for an <strong>Unix</strong> file )</p>
<p dir="auto">This time, if you click, successively, on the <strong>Find Next</strong> button, you’ll be able to see the <strong>different</strong> matches of the <strong>search</strong> regex !</p>
<p dir="auto">And, I did verify that the <strong>one-line</strong> script, below, <strong>without</strong> the <strong><code>^</code></strong> symbol, gives the <strong>expected</strong> text ;-))</p>
<pre><code class="language-py">editor.rereplace(r'(?s).*?(Bob|Ted)|(?s).*\z', r'?1\1\r\n')
</code></pre>
<p dir="auto">Best Regards</p>
<p dir="auto">guy038</p>
<p dir="auto"><strong>Two</strong> more points :</p>
<ul>
<li>Your <strong>new</strong> regex S/R :</li>
</ul>
<pre><code class="language-py">editor.rereplace(r'(?s)(Bob|Ted)|(?:.+?(?=(?1)))|(?:.+\z)', r'?1\1\r\n')
</code></pre>
<p dir="auto">works <strong>correctly</strong> because it does <strong>not</strong> contain any <strong><code>^</code></strong> assertion !</p>
<p dir="auto">but, would you had added the <strong><code>^</code></strong> <strong>symbol</strong>, like below :</p>
<pre><code class="language-py">editor.rereplace(r'(?s)(Bob|Ted)|(?:^.+?(?=(?1)))|(?:.+\z)', r'?1\1\r\n')
</code></pre>
<p dir="auto">it would had changed all your <strong>multi-lines</strong> example text as :</p>
<pre><code class="language-diff">Bob
</code></pre>
<ul>
<li>The <strong>lesson</strong> of that story is :</li>
</ul>
<p dir="auto">If you can <strong>properly</strong> visualize the <strong>different</strong> matches of a <strong>regex</strong> expression, as you <strong>expect</strong> to, when using the <strong><code>Find Next</code></strong> button, it’s likely that any <strong>replacement</strong> process, run from within a <strong><code>S/R</code> script</strong> command, should work <strong>nicely</strong>, too ;-))</p>
]]></description><link>https://community.notepad-plus-plus.org/post/51769</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/51769</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Fri, 27 Mar 2020 10:43:11 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Thu, 26 Mar 2020 15:10:08 GMT]]></title><description><![CDATA[<p dir="auto">More old thread revival…</p>
<p dir="auto">So I recently had a need for what is discussed in this thread, but I needed it embedded in a Pythonscript, and all I really needed was the logic conveyed by <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> with this solution:</p>
<p dir="auto"><img src="/assets/uploads/files/1585234139861-73e429e2-ebad-4f9e-afa6-4fc20ed9f426-image.png" alt="73e429e2-ebad-4f9e-afa6-4fc20ed9f426-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">So I figured out the <em>Your regex to match</em> part for my data; I’ll use <code>Bob|Ted</code> here for that for purposes of illustration, and of course some sample data:</p>
<pre><code>Alice Carol Alan Bob Ted
Ted Bob
Bob Carol Ted
Ted Carol
Alice Carol
Alice Bob
Bob
Alan Carol
Alan Alice
Bob Carol Alan
Alice
Bob Ted Alan
Alice Ted
Alan Ted
Ted Alan Alice Carol
Bob Ted Alice Carol
Bob Alan Alice Carol
Alan
Bob Ted Alan Carol
Ted
Alan Bob
Alice Carol Ted
Alice Bob Alan
Alice Bob Carol
Bob Carol
Bob Ted Alan Alice
Alice Ted Alan
Carol
Alice Carol Alan
Alice Bob Ted
Carol Ted Alan
</code></pre>
<p dir="auto">and I coded up the Pythonscript one-liner for it based on <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> 's regex:</p>
<pre><code>editor.rereplace(r'(?s)^.*?(Bob|Ted)|(?s).*\z', r'(?1\1\r\n)')
</code></pre>
<p dir="auto">and I thought I would end up with a number of lines with either <code>Bob</code> or <code>Ted</code> on them.  What actually happened was that I ended up with a single-line result of <code>Alice</code>!  Clearly, INCORRECT!  Or at least not what I needed.</p>
<p dir="auto">Digging in and working on it a bit, I found a correct way to achieve it in a Pythonscript replacement, and that is:</p>
<pre><code>editor.rereplace(r'(?s)(Bob|Ted)|(?:.+?(?=(?1)))|(?:.+\z)', r'?1\1\r\n')
</code></pre>
<p dir="auto">which, for the sample data above, yields the expected:</p>
<pre><code>Bob
Ted
Ted
Bob
Bob
Ted
Ted
Bob
Bob
Bob
Bob
Ted
Ted
Ted
Ted
Bob
Ted
Bob
Bob
Ted
Ted
Bob
Ted
Bob
Bob
Bob
Bob
Ted
Ted
Bob
Ted
Ted
</code></pre>
<p dir="auto">So, long story LONG, but I wanted to share that if anyone tries this technique <em><strong>using a script</strong></em>, the search regex to use might need to be altered to:</p>
<p dir="auto">SEARCH <code>(?s)(</code> <strong>Your regex to match</strong><code>)|(?:.+?(?=(?1)))|(?:.+\z)</code></p>
<p dir="auto">The REPLACE part is unchanged from what <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> provided.</p>
<p dir="auto">Note that I also tested it <em>interactively</em> in Notepad++'s <em>Replace</em> window and it works fine there as well, at least for my sample data.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/51760</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/51760</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 26 Mar 2020 15:10:08 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Tue, 21 Jan 2020 00:15:27 GMT]]></title><description><![CDATA[<p dir="auto">Hey all,</p>
<p dir="auto">I know this topic is quite old, anyway decided to share solution I’ve discovered (I’m not so technical, so Python script isn’t the option for me). So, long story short, I’ve extracted a long JSON response and needed to copy 95 URLs from it only and ignore everything else. Like in <a class="plugin-mentions-user plugin-mentions-a" href="/user/suncatcher" aria-label="Profile: Suncatcher">@<bdi>Suncatcher</bdi></a>’s case, everything was stored in a single line.</p>
<p dir="auto">So, I did the following:</p>
<ol>
<li>
<p dir="auto">Search for <code>https://site.com/project/(.*?)</code> regexp and replace all matches with <code>\r\nhttps://site.com/project/$1\r\n</code> so URLs were moved to separate lines;</p>
</li>
<li>
<p dir="auto">Afterward, switch to “Mark” tool, check “Bookmark line” option and mark all <code>https://site.com/project/(.*?)</code><br />
<img src="/assets/uploads/files/1579565061691-mark.png" alt="Mark.png" class=" img-fluid img-markdown" /></p>
</li>
<li>
<p dir="auto">Finally, click “Search” menu =&gt; <em>Bookmark</em> =&gt; <em>Remove unmarked lines</em></p>
</li>
</ol>
<p dir="auto">That’s it, list of necessary items only (URLs in my case) was created 🎉 My case is easier comparing to topic’s author, anyway hope this will be helpful for someone in the future, cheers!</p>
<p dir="auto">P.S. <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> thanks for mentioning <strong>Bookmark</strong> feature, I’ve never used it before and it’s super helpful</p>
]]></description><link>https://community.notepad-plus-plus.org/post/49991</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/49991</guid><dc:creator><![CDATA[Andriy Poznakhovskyy]]></dc:creator><pubDate>Tue, 21 Jan 2020 00:15:27 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Wed, 27 Jun 2018 23:47:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kashif-rana" aria-label="Profile: Kashif-Rana">@<bdi>Kashif-Rana</bdi></a></p>
<p dir="auto">Ummmm, well…No…that’s why the script was developed in the first place…seems like this should be obvious from the earlier postings in this thread…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/33210</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/33210</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Wed, 27 Jun 2018 23:47:52 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Wed, 27 Jun 2018 21:04:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a> I will try this script. But without script, is it possible to copy multiple instances of matched result (that is multi-line) by regex in a text file?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/33207</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/33207</guid><dc:creator><![CDATA[Kashif Rana]]></dc:creator><pubDate>Wed, 27 Jun 2018 21:04:11 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Wed, 27 Jun 2018 20:17:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kashif-rana" aria-label="Profile: Kashif-Rana">@<bdi>Kashif-Rana</bdi></a></p>
<p dir="auto">Have you actually read this thread from top to bottom?  If so, have you tried setting up and using <code>RedmarkedTextToClipboard2.py</code> above?  If I’m understanding your need correctly (still have my doubts) it seems as if that would solve the problem…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/33206</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/33206</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Wed, 27 Jun 2018 20:17:47 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Wed, 27 Jun 2018 19:57:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a> sorry for the confusion. What I want, whatever my regular expression matches, it is two line match (first line starts with ‘object’ and second line starts with ‘nat’). So like my regular expression will catch 100 instances of two lines below in huge file with other data as well and I want to copy that multi-line match.</p>
<p dir="auto">object network obj-192.168.236.13<br />
nat (DMZ1,outside) static 10.206.74.58 dns</p>
<p dir="auto">‘mark’ is marking all lines but ‘bookmark’ is only bookmarking first line, not second line so I cannot copy through bookmark.</p>
<p dir="auto">So question is how to copy all instances of multi-line match by regular expression?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/33204</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/33204</guid><dc:creator><![CDATA[Kashif Rana]]></dc:creator><pubDate>Wed, 27 Jun 2018 19:57:56 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Wed, 27 Jun 2018 12:57:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kashif-rana" aria-label="Profile: Kashif-Rana">@<bdi>Kashif-Rana</bdi></a> :</p>
<p dir="auto">Not sure exactly what you are asking but on your data this seems to work to match it:</p>
<p dir="auto"><strong>Find-what</strong> zone: <code>(?-s)^object.*\Rnat.*</code></p>
<p dir="auto">But what’s this about replacement?  This thread is just talking about matching text, redmarking it, and copying it…so I’m confused about what you want to do…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/33197</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/33197</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Wed, 27 Jun 2018 12:57:38 GMT</pubDate></item><item><title><![CDATA[Reply to Marked text manipulation on Tue, 26 Jun 2018 21:04:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a></p>
<p dir="auto">I am in the same situation but regular expression method is not working for me to copy match text.</p>
<p dir="auto">I want to grab all occurrences in configuration file where first line starts from ‘object’ and immediately second line starts with ‘nat’</p>
<p dir="auto">object network obj_any<br />
nat (inside,outside) dynamic interface<br />
object network obj-test<br />
nat (DMZ1,outside) static 10.206.49.180<br />
object network obj-192.168.236.200<br />
nat (DMZ1,outside) static 10.206.74.60<br />
object network obj-192.168.236.8<br />
nat (DMZ1,outside) static 10.206.49.183 tcp 8080 80<br />
object network obj-192.168.236.9<br />
nat (DMZ1,outside) static 10.206.49.178 tcp 1002 22<br />
object network obj-192.168.236.10<br />
nat (DMZ1,outside) static 10.206.49.178 tcp 8080 80<br />
object network obj-192.168.236.13<br />
nat (DMZ1,outside) static 10.206.74.58 dns</p>
<p dir="auto">I wrote regular expression ^object.<em>\R</em>\snat.* to grab both lines<br />
starting with ‘object’ and with ‘nat’ but when I am replacing it with<br />
(?1\1), it is deleting the matched lines. Any dea what could be the correct replace string to keep only matced two lines</p>
]]></description><link>https://community.notepad-plus-plus.org/post/33184</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/33184</guid><dc:creator><![CDATA[Kashif Rana]]></dc:creator><pubDate>Tue, 26 Jun 2018 21:04:35 GMT</pubDate></item></channel></rss>