<?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[Limit replace to bookmarked lines? Or something else...]]></title><description><![CDATA[<p dir="auto">I need to replace or delete a string on lines matching or containing another string. Working with cisco configs, need to remove log from all lines containing permit. I guess I need to limit replace to bookmarked lines? Help!</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/17550/limit-replace-to-bookmarked-lines-or-something-else</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 02:32:45 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/17550.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 01 May 2019 13:55:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Limit replace to bookmarked lines? Or something else... on Thu, 02 May 2019 17:18:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@PeterJones</a> said:</p>
<blockquote>
<p dir="auto">I’m not sure that “run a regex to bookmark, then run a PythonScript to edit” is any less confusing to the typical user than “run these 2-3 regex in sequence”</p>
</blockquote>
<p dir="auto">A difference of philosophy.  The OP already had his lines bookmarked, the script is decanted down to picking a menu item:  e.g. “ReplaceAllOnBookmarkedLinesOnly”.  So really it satisfies what was originally asked for, without a lot of mumbo-jumbo and smoke and mirrors with an obscure multistep regex (although those tools are good to have in one’s knowledge toolbox). :)</p>
<p dir="auto">Of course, there is the whole install-PS-if-you-don’t-have-it-already hurdle… ;)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/42841</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/42841</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 02 May 2019 17:18:04 GMT</pubDate></item><item><title><![CDATA[Reply to Limit replace to bookmarked lines? Or something else... on Thu, 02 May 2019 17:07:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a> said:</p>
<blockquote>
<p dir="auto">here’s a Pythonscript that fulfills the title of this thread;</p>
</blockquote>
<p dir="auto">Nice.</p>
<p dir="auto">I’m not sure that “run a regex to bookmark, then run a PythonScript to edit” is any less confusing to the typical user than “run these 2-3 regex in sequence”… but that’s still a good alternative.</p>
<p dir="auto">Really, with one more prompt at the beginning of your script ("Enter the keyword, such as ‘permit’: "), and using PythonScript to set the bookmarks rather than making the user manually bookmark, PythonScript could be made to handle it.  (Or, skipping bookmarks, just wrap the <code>editor.rereplace</code> inside of the <code>while</code> loop with pseudocode <code>if line contains KEYWORD then editor.rereplace</code>.)</p>
<p dir="auto">I made my mods, and was just about to post, when I re-read the title of the message, and it indicated “bookmarked lines”, so my avoiding of bookmarking my be going too far, in the OP’s opinion.  But since I’d already made the script changes, I might as well include it.</p>
<p dir="auto">----<br />
As you said, this won’t handle regex in the search/replace… but it does handle the simple case described in the original post, and goes a step further by not requiring marking the matching lines first.</p>
<pre><code># encoding=utf-8
"""in response to https://notepad-plus-plus.org/community/topic/17550"""
from Npp import *

keyword = notepad.prompt('Enter keyword to search for:', '', 'permit')
find_what = notepad.prompt('Enter text to find:', '', 'log')

if find_what != None and len(find_what) &gt; 0 and keyword != None and len(keyword)&gt;0:
    replace_with = notepad.prompt('Enter replacement text:', '', '')

    if replace_with != None:

        editor.beginUndoAction()
        nLines = editor.getLineCount()

        for line_nbr in range(0, nLines):
            start_pos = editor.positionFromLine(line_nbr)
            str = editor.getLine(line_nbr)
            end_pos = start_pos + len(str) - 1
            if keyword in str:
                editor.rereplace(find_what, replace_with, 0, start_pos, end_pos)

        editor.endUndoAction()
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/42840</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/42840</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 02 May 2019 17:07:44 GMT</pubDate></item><item><title><![CDATA[Reply to Limit replace to bookmarked lines? Or something else... on Thu, 02 May 2019 14:44:47 GMT]]></title><description><![CDATA[<p dir="auto">So in the spirit of my earlier reply, here’s a Pythonscript that fulfills the title of this thread; it is a bit simple-minded, but could easily be extended to handle regular expressions.</p>
<pre><code>bookmark_mask = 1 &lt;&lt; 24

if editor.markerNext(0, bookmark_mask) == -1:

    notepad.messageBox('To use this, need to have at least one bookmarked line; you have zero', '')

else:

    find_what = notepad.prompt('Enter text to find:', '', '')

    if find_what != None and len(find_what) &gt; 0:

        replace_with = notepad.prompt('Enter replacement text:', '', '')

        if replace_with != None:

            editor.beginUndoAction()

            line_nbr = editor.markerNext(0, bookmark_mask)
            while line_nbr != -1:
                start_pos = editor.positionFromLine(line_nbr)
                end_pos = start_pos + len(editor.getLine(line_nbr)) - 1
                editor.rereplace(find_what, replace_with, 0, start_pos, end_pos)
                line_nbr = editor.markerNext(line_nbr + 1, bookmark_mask)

            editor.endUndoAction()
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/42823</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/42823</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 02 May 2019 14:44:47 GMT</pubDate></item><item><title><![CDATA[Reply to Limit replace to bookmarked lines? Or something else... on Wed, 01 May 2019 17:37:55 GMT]]></title><description><![CDATA[<p dir="auto">Ha.  Well, I’ll qualify my earlier statement this way “no way to do it…in a very reasonable action”.  :)</p>
<p dir="auto">Most people that aren’t already fairly familiar with regex aren’t going to be able to follow some “complex” multi-step procedure.</p>
<p dir="auto">It still seems that some sample data from the OP could take this down to a really simple (for regex) single-step replacement.  Could be wrong, of course.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/42788</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/42788</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 01 May 2019 17:37:55 GMT</pubDate></item><item><title><![CDATA[Reply to Limit replace to bookmarked lines? Or something else... on Wed, 01 May 2019 15:29:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/15165">@J-T</a> , welcome to the Notepad++ Community forum.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a> said:</p>
<blockquote>
<p dir="auto">Well…no way to do it without scripting.</p>
</blockquote>
<p dir="auto">Though scripting is great, you can also do two-step or three-step regex, like@Terry-R suggested in <a href="https://notepad-plus-plus.org/community/topic/17541/regex-on-fixed-length-string-replacing-one-character" rel="nofollow ugc">the recent 32-character question</a>, which can overcome some of those limitations</p>
<p dir="auto">For example, assuming <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/15165">@J-T</a> 's data looks something like this</p>
<pre><code>This line has log but not the other keyword
This line has log in a line continaing permit
This line has permit and wants to remove log from it
This line has permit but not the word to remove
</code></pre>
<p dir="auto">The first regex should look for <code>(?-s)^(?=.*permit)</code> and replace with <code>EDITTHISLINE:</code><br />
The second regex could be something like <code>(?-s)(^EDITTHISLINE:)(.*)(log)(.*)$</code> with the replace of <code>\2\4</code> to delete the <code>EDITTHISLINE:</code> and the <code>log</code> from the line, but keep the other text from before and after <code>log</code>.  If there are still lines with <code>EDITTHISLINE:</code> prefix, the prefix can be removed with a third regex, <code>(?-s)^EDITTHISLINE:</code> replace with blank/empty.  (with some experimenting, I could probably get it down to be able to delete the EDITTHISLINE in the second regex, even if there is no <code>log</code>… but sometimes, if it’s simpler to understand, doing a third regex is worth it.)</p>
<p dir="auto">When I run those three regex, I get</p>
<pre><code>This line has log but not the other keyword
This line has  in a line continaing permit
This line has permit and wants to remove  from it
This line has permit but not the word to remove
</code></pre>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/15165">@J-T</a> :  This is a rough approximation based on your vague specs.  You may want to include whitespace before and/or after your match of <code>log</code>, to make spacing come out right, or something similar.</p>
<p dir="auto">-----<br />
FYI: I often add this to my response in regex threads, unless I am sure the original poster has seen it before.  Here is some helpful information for finding out more about regular expressions, and for formatting posts in this forum (especially quoting data) so that we can fully understand what you’re trying to ask:</p>
<blockquote>
<p dir="auto">This forum is formatted using <a href="https://daringfireball.net/projects/markdown/syntax" rel="nofollow ugc">Markdown</a>, with a help link buried on the little grey <code>?</code> in the COMPOSE window/pane when writing your post.  For more about how to use Markdown in this forum, please see <a href="https://notepad-plus-plus.org/community/topic/14262/how-to-markdown-code-on-this-forum/4" rel="nofollow ugc">@Scott-Sumner’s post in the “how to markdown code on this forum” topic</a>, and my updates <a href="https://notepad-plus-plus.org/community/topic/14262/how-to-markdown-code-on-this-forum/9" rel="nofollow ugc">near the end</a>.  It is very important that you use these formatting tips – using single backtick marks around small snippets, and using code-quoting for pasting multiple lines from your example data files – because otherwise, the forum will change normal quotes (<code>""</code>) to curly “smart” quotes (<code>“”</code>), will change hyphens to dashes, will sometimes hide asterisks (or if your text is <code>c:\folder\*.txt</code>, it will show up as <code>c:\folder*.txt</code>, missing the backslash).  If you want to clearly communicate your text data to us, you <em>need</em> to properly format it.</p>
</blockquote>
<blockquote>
<p dir="auto">If you have further search-and-replace (“matching”, “marking”, “bookmarking”, regular expression, “regex”) needs, study <a href="https://notepad-plus-plus.org/community/topic/15765/faq-desk-where-to-find-regex-documentation" rel="nofollow ugc">this FAQ</a> and the documentation it points to.  Before asking a new regex question, understand that for future requests, many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backward to get things working for you.  If you need help formatting, see the paragraph above.</p>
</blockquote>
<blockquote>
<p dir="auto">Please note that for all regex and related queries, it is best if you are explicit about what needs to match, <em>and</em> what <em>shouldn’t</em> match, and have multiple examples of both in your example dataset.  Often, what <em>shouldn’t match</em> helps define the regular expression as much or more than what <em>should match</em>.</p>
</blockquote>
]]></description><link>https://community.notepad-plus-plus.org/post/42781</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/42781</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 01 May 2019 15:29:27 GMT</pubDate></item><item><title><![CDATA[Reply to Limit replace to bookmarked lines? Or something else... on Wed, 01 May 2019 14:11:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a> said:</p>
<blockquote>
<p dir="auto">There is no way to scope a search to previously bookmarked lines</p>
</blockquote>
<p dir="auto">Well…no way to do it without scripting.  Scripting can do almost anything. :)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/42774</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/42774</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 01 May 2019 14:11:41 GMT</pubDate></item><item><title><![CDATA[Reply to Limit replace to bookmarked lines? Or something else... on Wed, 01 May 2019 14:04:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/15165">@J-T</a></p>
<p dir="auto">There is no way to scope a search to previously bookmarked lines, although wouldn’t that be nice?</p>
<p dir="auto">If you care to share some data with some good before and after examples, perhaps something could be crafted to do the job all in one operation…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/42773</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/42773</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 01 May 2019 14:04:10 GMT</pubDate></item></channel></rss>