<?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[Notepad++ Regex to find files having more than 2 words but should exclude certain word]]></title><description><![CDATA[<p dir="auto">I have below files<br />
File 1<br />
hjsakh<br />
hasj<br />
ashjh <strong>word1</strong> sadhjhf<br />
asgdga<br />
ashsad<br />
sj <strong>word3a</strong> sdha<br />
ajsh<br />
ashjh<br />
<strong>word2a</strong></p>
<p dir="auto">File 2<br />
hjsakh<br />
hasj<br />
ashjh <strong>word1</strong> sadhjhf<br />
asgdga<br />
ashsad<br />
<strong>word2a</strong><br />
sdhfj<br />
sj <strong>word3b</strong> sdha<br />
ajsh<br />
ashjh</p>
<p dir="auto">File 3<br />
hjsakh<br />
hasj<br />
ashjh <strong>word1</strong> sadhjhf<br />
asgdga<br />
ashsad<br />
<strong>word2b</strong><br />
sdh<br />
sj sdha<br />
ajsh<br />
ashjh</p>
<p dir="auto">File 4<br />
hjsakh<br />
hasj<br />
asgdga<br />
ashsad<br />
<strong>word2c</strong><br />
sdh<br />
sj sdha<br />
ajsh<br />
ashjh<br />
ashjh <strong>word1</strong> sadhjhf</p>
<p dir="auto">File 5<br />
hjsakh<br />
hasj<br />
ashjh <strong>word1</strong> sadhjhf<br />
asgdga<br />
ashsad<br />
<strong>word3a</strong><br />
sdh<br />
sj sdha<br />
ajsh<br />
ashjh</p>
<p dir="auto">File 6<br />
hjsakh<br />
hasj<br />
<strong>word3b</strong><br />
ashjh <strong>word1</strong> sadhjhf<br />
asgdga<br />
ashsad<br />
sdh<br />
sj sdha<br />
ajsh<br />
ashjh</p>
<p dir="auto">looking for regex which can find files which satisfy this criteria (contains word1) &amp; (contains word2a or word2b or word2c) &amp; (does not contain word3a and word3b). In above example it should find only File 3 and File 4</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/25476/notepad-regex-to-find-files-having-more-than-2-words-but-should-exclude-certain-word</link><generator>RSS for Node</generator><lastBuildDate>Wed, 19 Aug 2026 07:59:03 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/25476.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 15 Feb 2024 15:46:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Notepad++ Regex to find files having more than 2 words but should exclude certain word on Thu, 15 Feb 2024 18:20:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mkupper" aria-label="Profile: mkupper">@<bdi>mkupper</bdi></a> said in <a href="/post/92906">Notepad++ Regex to find files having more than 2 words but should exclude certain word</a>:</p>
<blockquote>
<p dir="auto">It turns out that the not scanner, (?!word3a|word3b) only works on lines, not files, even if you try ``(?-s)(?!word3a|word3b).</p>
</blockquote>
<p dir="auto">You’re misunderstanding what is going wrong. The expression you gave says, “Match null here if the following characters aren’t either <strong><code>word3a</code></strong> or <strong><code>word3b</code></strong>.” That matches at every position in a file <em>except</em> immediately before <strong><code>word3a</code></strong> or <strong><code>word3b</code></strong>. (Each line is listed once in the search results, but look at the number of hits.) What is needed is <strong><code>(?s)\A(?!.*(word3a|word3b))</code></strong>, which says, “Match null at the beginning of the document if the following characters don’t match <em>any number of arbitrary characters followed by either <strong><code>word3a</code></strong> or <strong><code>word3b</code></strong></em>.”</p>
<p dir="auto">When I tested the whole expression I got some erratic results when I had it match null, which is why I set it to match the string from the beginning up to the word <strong><code>word1</code></strong>.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/92908</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/92908</guid><dc:creator><![CDATA[Coises]]></dc:creator><pubDate>Thu, 15 Feb 2024 18:20:02 GMT</pubDate></item><item><title><![CDATA[Reply to Notepad++ Regex to find files having more than 2 words but should exclude certain word on Thu, 15 Feb 2024 18:29:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jignesh-waghela" aria-label="Profile: Jignesh-Waghela">@<bdi>Jignesh-Waghela</bdi></a> said in <a href="/post/92905">Notepad++ Regex to find files having more than 2 words but should exclude certain word</a>:</p>
<blockquote>
<p dir="auto">looking for regex which can find files which satisfy this criteria (contains word1) &amp; (contains word2a or word2b or word2c) &amp; (does not contain word3a and word3b). In above example it should find only File 3 and File 4</p>
</blockquote>
<p dir="auto">Try:</p>
<p dir="auto"><strong><code>(?s)\A(?=.*(word2a|word2b|word2c))(?!.*(word3a|word3b)).*word1</code></strong></p>
<p dir="auto"><strong>Edit to add:</strong></p>
<p dir="auto"><strong><code>(?s)\A(?=.*?\b(word2a|word2b|word2c)\b)(?!.*?\b(word3a|word3b)\b).*?\bword1\b</code></strong></p>
<p dir="auto">is probably better. The <strong><code>\b</code></strong> assertions require word boundaries — so that <strong><code>reword2a</code></strong> or <strong><code>word13</code></strong> won’t count. Changing <strong><code>.*</code></strong> to <strong><code>.*?</code></strong> won’t change the results, but it <em>might</em> make the expressions more efficient and less likely to run into “expression too complex” failures.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/92907</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/92907</guid><dc:creator><![CDATA[Coises]]></dc:creator><pubDate>Thu, 15 Feb 2024 18:29:42 GMT</pubDate></item><item><title><![CDATA[Reply to Notepad++ Regex to find files having more than 2 words but should exclude certain word on Thu, 15 Feb 2024 17:28:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jignesh-waghela" aria-label="Profile: Jignesh-Waghela">@<bdi>Jignesh-Waghela</bdi></a> Regular expressions tend to be read from left to write and intend to match patterns that are scanned left to right. As you watch to match things where the words appear in any order I would do this in several passes rather than constructing a rather long regexp that has all the possible orders of words and their conditions.</p>
<p dir="auto">My passes were:</p>
<ol>
<li>Scan for files containing <strong>word1</strong>. Either make a list of these.  It turns out all of your files contain <strong>word1</strong>.</li>
<li>Scan the list of files from step 1 for <code>(word2a|word2b|word2c)</code> - We are down to a second list that has files 1, 2, 3, and 4.</li>
<li>It turns out that the <code>not</code> scanner, <code>(?!word3a|word3b)</code> only works on lines, not files, even if you try ``(?-s)(?!word3a|word3b)<code>.  Thus I would scan list 2 for </code>(word3a|word3b)` and exclude those.  This excludes files 1, 2, and also 5 and 6 but those are not in list 2.  The remaining files are 3 and 4.</li>
</ol>
]]></description><link>https://community.notepad-plus-plus.org/post/92906</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/92906</guid><dc:creator><![CDATA[mkupper]]></dc:creator><pubDate>Thu, 15 Feb 2024 17:28:53 GMT</pubDate></item></channel></rss>