<?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[Find and Replace mass delete groups of lines that doesn&#x27;t have specific word]]></title><description><![CDATA[<p dir="auto">So i have do not know how to use the Find and Replace to mass delete the groups that doesn’t have “Keepinfo”</p>
<p dir="auto">Example:</p>
<pre><code class="language-txt">{
   "model": "PartA/NameA",
  "predicate": {
    "model_data": 1234
  }
},
{
  "model": "PartA/KeepInfo/NameA",
  "predicate": {
    "model_data": 1234
  }
},
{
   "model": "PartA/Name-B",
  "predicate": {
    "model_data": 2345678
  }
},
{
  "model": "PartA/KeepInfo/Name-B",
  "predicate": {
    "model_data": 2345678
  }
},
</code></pre>
<p dir="auto">-–</p>
<p dir="auto"><em>moderator added code markdown around text; please don’t forget to <a href="https://community.notepad-plus-plus.org/topic/21925/faq-desk-formatting-forum-posts">use the <code>&lt;/&gt;</code> button to mark example text as “code”</a> so that characters don’t get changed by the forum</em></p>
]]></description><link>https://community.notepad-plus-plus.org/topic/24468/find-and-replace-mass-delete-groups-of-lines-that-doesn-t-have-specific-word</link><generator>RSS for Node</generator><lastBuildDate>Wed, 20 May 2026 22:50:35 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/24468.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 16 May 2023 07:07:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Find and Replace mass delete groups of lines that doesn&#x27;t have specific word on Tue, 16 May 2023 15:42:59 GMT]]></title><description><![CDATA[<p dir="auto">I like the solutions proposed above because they are relatively simple and to-the-point. However, regex-replaces on JSON in general get pretty hairy due to factors <em>including but not limited to:</em></p>
<ul>
<li>how do you differentiate between a pattern in a key versus a string?</li>
<li>how do you take into account the fact that JSON doesn’t care about the order of keys whereas regexes do?</li>
<li>what if there are <code>]</code> or <code>}</code> inside strings, such that the regex is fooled into thinking the JSON object ended?</li>
</ul>
<p dir="auto">Just to illustrate how annoying regex-replaces get once you start trying to satisfy all the syntactic requirements of JSON, here’s a regex-replace I came up with to achieve this <em>while ignoring insignificant whitespace and the order of keys and removing any trailing commas:</em><br />
find/replace <code>(?-i),\s*{(?:[^{]*{[^}]*}\s*,\s*"model"\s*:\s*"[^"]*KeepInfo[^"]*"\s*|\s*"model"\s*:\s*"[^"]*KeepInfo[^"]*"[^{]*{[^}]*}\s*)}\s*(,)?</code> with <code>\1</code>.</p>
<p dir="auto"><a href="https://github.com/molsonkiko/JsonToolsNppPlugin" rel="nofollow ugc">JsonTools</a> is a fine solution for this, if you’re able to use plugins.</p>
<p dir="auto">Because it uses a JSON parser to parse the JSON, it is insensitive to the formatting of the JSON.</p>
<p dir="auto">To filter JSON with the plugin, just use <code>Alt-P-J-J</code> (tap the keys in sequence, don’t hold them down simultaneously) to open the tree view, then enter one of the following queries into the query box and hit <code>Ctrl+Enter</code>, then <code>Save query result</code>.<br />
Two queries that accomplish your goals:<br />
<code>@[:][not(@.model =~ `(?i)keepinfo`)]</code> filters out objects where the <code>model</code> includes <code>keepinfo</code> <em>ignoring case</em>.<br />
<code>@[:][not(@.model =~ KeepInfo)]</code> filters out objects where the <code>model</code> includes <code>KeepInfo</code> <em>in that case only</em>.</p>
<p dir="auto">While I’m here, PythonScript is also an efficient solution:</p>
<pre><code>import json
from Npp import editor

j = json.loads(txt)
filtered = [o for o in j if 'KeepInfo' in o['model']]
filtered_text = json.dumps(filtered, indent=4)
editor.setText(filtered_text)
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/86382</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86382</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Tue, 16 May 2023 15:42:59 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace mass delete groups of lines that doesn&#x27;t have specific word on Tue, 16 May 2023 13:28:02 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/nguyen-quang" aria-label="Profile: nguyen-quang">@<bdi>nguyen-quang</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: peterjones">@<bdi>peterjones</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">Yes, indeed, I was mistaken  in my <strong>first</strong> post and <a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: peterjones">@<bdi>peterjones</bdi></a> is <strong>right</strong> : you must <strong>check</strong> the <strong><code>Bookmark</code></strong> option, too !</p>
<hr />
<p dir="auto">Ah…, <strong>Peter</strong>, your regex S/R just aims <strong>exactly</strong> for the OP’s goal and should be <strong>quicker</strong> than mine. Good point :-))</p>
<p dir="auto">In <strong>free-spacing</strong> mode, your regex can be expressed as :</p>
<p dir="auto">SEARCH <strong><code>(?xis) ^ { (?: (?! KeepInfo ) . )*? ^ },</code></strong></p>
<p dir="auto">REPLACE <strong><code>Leave Empty</code></strong></p>
<p dir="auto">BR</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86378</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86378</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 16 May 2023 13:28:02 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace mass delete groups of lines that doesn&#x27;t have specific word on Tue, 16 May 2023 13:08:59 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> said in <a href="/post/86375">Find and Replace mass delete groups of lines that doesn’t have specific word</a>:</p>
<blockquote>
<p dir="auto">Search &gt; Bookmark &gt; Inverse Bookmark</p>
</blockquote>
<p dir="auto">For that to work, you also have to have the <code>Bookmark line</code> checkbox checkmarked… but your instructions said to not have it checkmarked.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86377</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86377</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 16 May 2023 13:08:59 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace mass delete groups of lines that doesn&#x27;t have specific word on Tue, 16 May 2023 13:06:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/nguyen-quang" aria-label="Profile: Nguyen-Quang">@<bdi>Nguyen-Quang</bdi></a> said in <a href="/post/86366">Find and Replace mass delete groups of lines that doesn’t have specific word</a>:</p>
<blockquote>
<p dir="auto">how to use the Find and Replace to mass delete the groups that doesn’t have “Keepinfo”</p>
</blockquote>
<p dir="auto">Assuming each group starts with <code>{</code> <em>at the beginning of the line</em> as your example shows (no whitespace prefix) and each group ends with <code>},</code> _at the beginning of the line as your example shows (no whitespace prefix), then I would do the “simple” version:</p>
<ul>
<li>FIND WHAT = <code>(?is)^{(?:(?!KeepInfo).)*?^},</code></li>
<li>REPLACE WITH = (leave box empty)</li>
<li>SEARCH MODE = Regular Expression</li>
</ul>
<p dir="auto">I used <code>(?is)</code> to make sure <code>. matches newline</code> is on no matter what the state of your checkbox is, and to make sure <code>match case</code> is off no matter what the state of your checkbox is.  I made it case insensitive because your data had <code>KeepInfo</code> but your statement was <code>doesn't have "Keepinfo"</code> – so since I couldn’t be sure of whether all the <code>I</code> from <code>KeepInfo</code> would be upper case, I made the search case insensitive.</p>
<p dir="auto">My guess is that my assumptions will be too restrictive for your actual data, but this matches what you showed us, so…</p>
<p dir="auto">Good luck.</p>
<p dir="auto">-—</p>
<h3>Useful References</h3>
<ul>
<li><a href="https://community.notepad-plus-plus.org/topic/21965/please-read-before-posting">Please Read Before Posting</a></li>
<li><a href="https://community.notepad-plus-plus.org/topic/22022/template-for-search-replace-questions">Template for Search/Replace Questions</a></li>
<li><a href="https://community.notepad-plus-plus.org/topic/21925/faq-desk-formatting-forum-posts">Formatting Forum Posts</a></li>
<li><a href="https://npp-user-manual.org/docs/searching/#regular-expressions" rel="nofollow ugc">Notepad++ Online User Manual: Searching/Regex</a></li>
<li><a href="https://community.notepad-plus-plus.org/topic/15765/faq-desk-where-to-find-regular-expressions-regex-documentation">FAQ: Where to find other regular expressions (regex) documentation</a></li>
</ul>
]]></description><link>https://community.notepad-plus-plus.org/post/86376</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86376</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 16 May 2023 13:06:15 GMT</pubDate></item><item><title><![CDATA[Reply to Find and Replace mass delete groups of lines that doesn&#x27;t have specific word on Tue, 16 May 2023 13:02:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/nguyen-quang" aria-label="Profile: nguyen-quang">@<bdi>nguyen-quang</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">I suppose that <strong>marking</strong> the lines which contain the <strong><code>KeepInfo</code></strong> string as well as the <strong>subsequent</strong> lines of the <strong>same</strong> group is the <strong>best</strong> bet !</p>
<hr />
<p dir="auto">So follow the <strong>steps</strong> below :</p>
<ul>
<li>
<p dir="auto">Open your file in Notepad++</p>
</li>
<li>
<p dir="auto">Open the <strong>Mark</strong> dialog ( <strong><code>Ctrl + M</code></strong> )</p>
</li>
<li>
<p dir="auto">Type in the regex <strong><code>(?x-is) ^ { \R .+ KeepInfo .+ \R (?: .+ \R)+? (?= { | \Z )</code></strong> in the <strong>Find what:</strong> zone</p>
</li>
<li>
<p dir="auto"><strong>Uncheck</strong> all box options</p>
</li>
<li>
<p dir="auto"><strong>Check</strong> the <strong><code>Purge for each search</code></strong> and <strong><code>Wrap around</code></strong> options <strong>only</strong> !</p>
</li>
<li>
<p dir="auto">Select the <strong><code>Regular expression </code></strong> search <strong>mode</strong></p>
</li>
<li>
<p dir="auto">Click on the <strong><code>Mark All</code></strong> button</p>
</li>
<li>
<p dir="auto">Then, click on the <strong><code>Search &gt; Bookmark &gt; Inverse Bookmark</code></strong> menu option</p>
</li>
<li>
<p dir="auto">Finally, click on the <strong><code>Search &gt; Bookmark &gt; Remove Bookmark lines</code></strong> menu option</p>
</li>
</ul>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
<p dir="auto">Oh ! An <strong>other</strong> solution could be :</p>
<ul>
<li>
<p dir="auto">Right after the <strong><code>Mark All</code></strong> operation, click on the <strong><code>Copy Marked Text</code></strong> button</p>
</li>
<li>
<p dir="auto">Open a <strong>new</strong> tab ( <strong><code>Ctrl + N</code></strong> )</p>
</li>
<li>
<p dir="auto">Paste the <strong>clipboard</strong> contents ( <strong><code>Ctrl + V</code></strong> )</p>
</li>
<li>
<p dir="auto">Execute the simple <strong>regex</strong> S/R to delete the <strong>separation</strong> lines between <strong>each</strong> block :</p>
</li>
</ul>
<p dir="auto">SEARCH <strong><code>^\R----\R</code></strong></p>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
]]></description><link>https://community.notepad-plus-plus.org/post/86375</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86375</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 16 May 2023 13:02:42 GMT</pubDate></item></channel></rss>