<?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[Regular expression to find two words in files in folder]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I need to look for two words in a set of files in a folder.<br />
using<br />
(Word1) | (word2)<br />
I find files that contain either word1 or word2 as but I need to find<br />
Only files that contain word1 and word2 together ignoring all other files.<br />
Thanks for your cooperation</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/13518/regular-expression-to-find-two-words-in-files-in-folder</link><generator>RSS for Node</generator><lastBuildDate>Tue, 12 May 2026 18:11:12 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/13518.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 24 Mar 2017 16:30:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regular expression to find two words in files in folder on Mon, 27 Mar 2017 22:33:54 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/vasile-caraus" aria-label="Profile: vasile-caraus">@<bdi>vasile-caraus</bdi></a>,</p>
<p dir="auto">Now, I realized that the regex, given in my <strong>previous</strong> post, <strong><code>(?i-s)(Word1).*?(Word2)|(?2).*?(?1)</code></strong>  could be simplified !</p>
<p dir="auto">Indeed, as I explained, we can’t use <strong>back-references</strong>, which are <strong>not</strong> defined if the regex engine choose the <strong>second</strong> alternative ! But, when the boundaries <strong>Word1</strong> and <strong>Word2</strong> are <strong>not</strong>, themselves, regexes ( as, for instance <strong><code>\d+</code></strong>, <strong><code>a..z</code></strong>… ) and rather <strong>simple</strong> strings, we can use the <strong>more simple</strong> syntax below :</p>
<p dir="auto"><strong><code>(?i-s)Word1.*?Word2|Word2.*?Word1</code></strong></p>
<hr />
<p dir="auto">Secondly, to select any <strong>entire</strong> line ( with its <strong>EOL</strong> characters ) containing the <strong>two</strong> words <strong><code>Word1</code></strong> and <strong><code>Word2</code></strong>, whatever their order, use the regex, below :</p>
<p dir="auto"><strong><code>(?i-s)^.*(Word1.*Word2|Word2.*Word1).*\R</code></strong></p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
<p dir="auto"><strong>P.S.</strong> :</p>
<p dir="auto">As we’re rather dealing with <strong>exact</strong> words, we should use, instead of the <strong>two</strong> above, the regexes, below :</p>
<p dir="auto"><strong><code>(?i-s)(?&lt;=\W)Word1\W.*?\WWord2(?=\W)|(?&lt;=\W)Word2\W.*?\WWord1(?=\W)</code></strong></p>
<p dir="auto">and</p>
<p dir="auto"><strong><code>(?i-s)^.*\W(Word1\W.*\WWord2|Word2\W.*\WWord1)\W.*\R</code></strong></p>
]]></description><link>https://community.notepad-plus-plus.org/post/23115</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23115</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Mon, 27 Mar 2017 22:33:54 GMT</pubDate></item><item><title><![CDATA[Reply to Regular expression to find two words in files in folder on Mon, 27 Mar 2017 21:36:42 GMT]]></title><description><![CDATA[<p dir="auto">Try <code>(?x)(?ms)((test_date.*?2005).*?(client_info.*?JESI))|(\2.*?\1)</code></p>
<p dir="auto">In case  <code>word1</code>and <code>word2</code>are names of variable rather than values, I don’t know.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23113</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23113</guid><dc:creator><![CDATA[Per Isakson]]></dc:creator><pubDate>Mon, 27 Mar 2017 21:36:42 GMT</pubDate></item><item><title><![CDATA[Reply to Regular expression to find two words in files in folder on Mon, 27 Mar 2017 20:01:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/andrea-cappelli" aria-label="Profile: Andrea-Cappelli">@<bdi>Andrea-Cappelli</bdi></a> said:</p>
<blockquote>
<p dir="auto">JESI</p>
</blockquote>
<p dir="auto">word1 = Jesi<br />
word2 = 2005</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23109</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23109</guid><dc:creator><![CDATA[Andrea Cappelli]]></dc:creator><pubDate>Mon, 27 Mar 2017 20:01:12 GMT</pubDate></item><item><title><![CDATA[Reply to Regular expression to find two words in files in folder on Mon, 27 Mar 2017 18:37:45 GMT]]></title><description><![CDATA[<p dir="auto">Why do you try to match what’s between the word1 and two with <code>(?s:.?)</code>, which only matches zero or one character? Replace it by <code>(?s:.*?)</code> and <code>word1</code> and <code>word2</code> by <code>client_info</code> and  <code>test_date</code>, respectively. That will make your example work.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23107</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23107</guid><dc:creator><![CDATA[Per Isakson]]></dc:creator><pubDate>Mon, 27 Mar 2017 18:37:45 GMT</pubDate></item><item><title><![CDATA[Reply to Regular expression to find two words in files in folder on Mon, 27 Mar 2017 17:34:49 GMT]]></title><description><![CDATA[<p dir="auto">and where are <code>word1</code> and <code>word2</code> in your text?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23106</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23106</guid><dc:creator><![CDATA[Vasile Caraus]]></dc:creator><pubDate>Mon, 27 Mar 2017 17:34:49 GMT</pubDate></item><item><title><![CDATA[Reply to Regular expression to find two words in files in folder on Mon, 27 Mar 2017 16:43:16 GMT]]></title><description><![CDATA[<p dir="auto">With some experience for me as it gave me the best results is this</p>
<p dir="auto">(word1)(?s:.<em>?)(word2)|(word2)(?s:.</em>?)(word1)</p>
<p dir="auto">But I see that the discussion gets interesting then I write the whole issue.<br />
I file like this<br />
…<br />
latest_meas_value(‘R’,“LY1-2”,81,81,0,0,“”,1)<br />
latest_meas_value(‘R’,“H-H”,85,85,0,0,“”,1)<br />
tankitem(“+ESSENZE FLOREALI     (alt E)”,1,1)<br />
tankitem(“+Bryaconeel (Tabl)”,1,1)<br />
tankitem(“+Aesculus compositum (Drops)”,1,1)<br />
tankitem(“+Viscum compositum mite”,1,1)<br />
tankitem(“+Bryaconeel (Tabl)”,2,1)<br />
tankitem(“+Aesculus compositum (Drops)”,2,1)<br />
tankitem(“+Viscum compositum mite”,2,1)<br />
op_name(“OK”)<br />
starting_time(12,15)<br />
client_info(“NAME AND SURNAME”,“”,“JESI”,“”,“13.07.1926”,“”,“Clinic”)<br />
test_date(“8/10/1995”)<br />
memo_pad(“LONG DESCRIPTION\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n”,4,13)<br />
elapsed_time(1)</p>
<p dir="auto">Of these files should I look for<br />
JESI<br />
and<br />
2005<br />
Jesi only in the line “client_info” and 2005 only in the line “test_date”<br />
Any ideas?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23102</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23102</guid><dc:creator><![CDATA[Andrea Cappelli]]></dc:creator><pubDate>Mon, 27 Mar 2017 16:43:16 GMT</pubDate></item><item><title><![CDATA[Reply to Regular expression to find two words in files in folder on Mon, 27 Mar 2017 08:04:59 GMT]]></title><description><![CDATA[<p dir="auto">Andreea Cappelli,  I test you last regex, I am glad to here that works, but I don’t know in what case exactly. I have a file with Word1 and Word2 on different lines in the same file, and doesn’t work you regex. So, tell us how it looks your file.</p>
<p dir="auto">guy38, about your very fine regex <code>(?i-s)(Word1).*?(Word2)|(?2).*?(?1)</code> this selects everything from word1 and word2 on the same line. Perfect.</p>
<p dir="auto">Now, I change a little bit your regex, so I can select the entire line that contains Word1 and Word2.</p>
<p dir="auto"><code>^.*(?i-s)(Word1).*?(Word2)|(?2).*?(?1).*$</code> but doesn’t work too good. It selects everything till Word2, but not everything after him. Can you look a little bit?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23084</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23084</guid><dc:creator><![CDATA[Vasile Caraus]]></dc:creator><pubDate>Mon, 27 Mar 2017 08:04:59 GMT</pubDate></item><item><title><![CDATA[Reply to Regular expression to find two words in files in folder on Sun, 26 Mar 2017 17:23:30 GMT]]></title><description><![CDATA[<p dir="auto">Thank you very much for the explanation. The expression suits me in this form</p>
<p dir="auto">(?si)(Word1)(?=.<em>?(Word2))|(?2)(?=.</em>?(?1))</p>
<p dir="auto">Thanks again</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23071</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23071</guid><dc:creator><![CDATA[Andrea Cappelli]]></dc:creator><pubDate>Sun, 26 Mar 2017 17:23:30 GMT</pubDate></item><item><title><![CDATA[Reply to Regular expression to find two words in files in folder on Sat, 25 Mar 2017 12:08:16 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/andrea-cappelli" aria-label="Profile: andrea-cappelli">@<bdi>andrea-cappelli</bdi></a>,</p>
<p dir="auto">The regex given by <a class="plugin-mentions-user plugin-mentions-a" href="/user/per-isakson" aria-label="Profile: per-isakson">@<bdi>per-isakson</bdi></a> is quite <strong>correct</strong>. However when the general case where the two words <strong><code>Word1</code></strong> and <strong><code>Word2</code></strong> are located in <strong>different</strong> lines, a search, with the <strong>Find in Files</strong> dialog, does <strong>NOT</strong> display, in the <strong>Find Result</strong> panel, <strong>all</strong> the lines of the block, beginning with <strong><code>Word1</code></strong> and ending with <strong><code>Word2 </code></strong> ( or the <strong>opposite</strong> ) but ONLY the <strong>first</strong> line of each <strong>multi-lines</strong> block. ( small bug ! )</p>
<p dir="auto">So, instead, you could use the regex <strong><code>(?si)(Word1)(?=.*?(Word2))|(?2)(?=.*?(?1))</code></strong>, which searches for, either, the words <strong><code>Word1</code></strong> OR <strong><code>Word2</code></strong>, in an <strong>insensitive case</strong> way, if they are followed, further on, by the <strong>second specific</strong> word</p>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">The syntax <strong><code>(?si)</code></strong>, at <strong>beginning</strong> of the regex, are <strong>modifiers</strong> which ensures that :</p>
<ul>
<li>
<p dir="auto">The <strong>dot</strong> ( <strong><code>.</code></strong> ) special character matches, absolutely, <strong>any single</strong> character ( <strong>standard</strong> or <strong>EOL</strong> )</p>
</li>
<li>
<p dir="auto">The search will be perform, in an <strong>insensitive case</strong> way ( If you need a <strong>sensitive</strong> search, just use the syntax <strong><code>(?s-i)</code></strong> )</p>
</li>
</ul>
</li>
<li>
<p dir="auto">Then <strong><code>(Word1)</code></strong> matches the string <strong><code>Word1</code></strong>, stored as <strong>group 1</strong>, due to the <strong>parentheses</strong>, ONLY IF followed by the <strong>first</strong> string <strong><code>Word2</code></strong>, found afterwards, also stored as <strong>group 2</strong>, due to the <strong>“Look-ahead”</strong> construction <strong><code>(?=.*?(Word2))</code></strong></p>
</li>
<li>
<p dir="auto">After the <strong>alternative</strong> symbol <strong><code>|</code></strong>, the case <strong><code>(?2)(?=.*?(?1))</code></strong> just represents the <strong>opposite</strong> case, where we’re searching for the string <strong><code>Word2</code></strong>, followed, further on, with the string <strong><code>Word1</code></strong>. We use a <strong>specific</strong> regex construction <strong><code>(?#)</code></strong>, named a <strong>called subpattern</strong>. ( This <strong>atomic</strong> group is just a particular case of of <strong>recursive</strong> subpattern, located <strong>outside</strong> the parentheses to which it <strong>refers</strong> )</p>
</li>
</ul>
<hr />
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/andrea-cappelli" aria-label="Profile: andrea-cappelli">@<bdi>andrea-cappelli</bdi></a>, if your <strong>two</strong> words, <strong><code>Word1</code></strong> and <strong><code>Word2</code></strong>, are, always, both located in a <strong>same</strong> line, you could, preferably, use the more <strong>simple</strong> regex, below, which searches for the <strong>smaller</strong> range of characters, in a <strong>same</strong> line, between the string <strong><code>Word1</code></strong> and <strong><code>Word2</code></strong> OR between <strong><code>Word2</code></strong> and <strong><code>Word1</code></strong></p>
<p dir="auto"><strong><code>(?i-s)(Word1).*?(Word2)|(?2).*?(?1)</code></strong></p>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">The <strong><code>(?i-s)</code></strong> modifiers ensures that :</p>
<ul>
<li>
<p dir="auto">The search is performed, in an *<strong>insensitive case</strong> way</p>
</li>
<li>
<p dir="auto">The <strong>dot</strong> will match a <strong>single standard</strong> character, even if you <strong>previously</strong> checked the <strong>. matches newline</strong> option</p>
</li>
</ul>
</li>
<li>
<p dir="auto">If you need a <strong>sensitive</strong> search, change the <strong>modifiers</strong> part by the syntax <strong><code>(?-is)</code></strong></p>
</li>
</ul>
<hr />
<p dir="auto">After running these regexes, using the <strong>Find in Files</strong> dialog, you should get, in the <strong>Find result</strong> panel :</p>
<ul>
<li>
<p dir="auto">The <strong>absolute path</strong> of each file, containing the <strong>two</strong> words <strong><code>Word1</code></strong> and <strong><code>Word2</code></strong></p>
</li>
<li>
<p dir="auto">Some lines, containing, <strong>either</strong>, <strong><code>Word1</code></strong> or <strong><code>Word2</code></strong> or <strong>both</strong></p>
</li>
</ul>
<p dir="auto">If you, simply, need the list of <strong>all</strong> these files, follow the method, below :</p>
<ul>
<li>
<p dir="auto">With a <strong>right</strong> mouse click, choose the <strong>select All</strong> option, in the <strong>Find result</strong> panel</p>
</li>
<li>
<p dir="auto">Hit the <strong><code>Ctrl + C</code></strong> shortcut ( <strong>DO NOT</strong> use the context option <strong>Copy</strong> ! )</p>
</li>
<li>
<p dir="auto"><strong>Paste</strong> the <strong>clipboard</strong> contents in a <strong>new</strong> tab, with the <strong><code>Ctrl + V</code></strong> shortcut</p>
</li>
<li>
<p dir="auto">In this <strong>new</strong> tab, perform the simple <strong>S/R</strong>, below :</p>
</li>
</ul>
<p dir="auto">SEARCH <strong><code>^\t.+\R</code></strong></p>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
<p dir="auto">P.S. :</p>
<p dir="auto">It’s very <strong>important</strong> to understand the <strong>fundamental</strong> difference between a <strong>subpattern</strong>, used as a <strong>subroutine</strong> and a <strong>back reference</strong> !!</p>
<p dir="auto">For instance, given the <strong>four</strong> lines text, below :</p>
<pre><code class="language-json">123abc123
123abc789
789abc123
789abc789
</code></pre>
<p dir="auto">The regex <strong><code>(\d+)abc\1</code></strong>, with the <strong><code>\1</code></strong> <strong>back-reference</strong>, would match the <strong>first</strong> and <strong>fourth</strong> line, only. Indeed, the syntax <strong><code>\1</code></strong> refers to the <strong>present</strong> value of the <strong>group 1</strong></p>
<p dir="auto">Whereas the regex <strong><code>(\d+)abc(?1)</code></strong>, with the <strong><code>(?1)</code></strong> <strong>called subpattern</strong>, would match the <strong>four</strong> lines ! Actually, this <strong>second</strong> regex syntax is,simply, <strong>identical</strong> to the regex <strong><code>(\d+)abc\d+</code></strong> ;-))</p>
<p dir="auto"><strong>P.P.S.</strong> :</p>
<p dir="auto">After preparing this post, I found out that a <strong>previous</strong> post, more <strong>detailed</strong>, at the address, below, just speak about a <strong>very similar</strong> problem !!!</p>
<p dir="auto"><a href="https://notepad-plus-plus.org/community/topic/12948/2-search-strings-in-a-group-of-files-with-the-search-function" rel="nofollow ugc">https://notepad-plus-plus.org/community/topic/12948/2-search-strings-in-a-group-of-files-with-the-search-function</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/23034</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23034</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sat, 25 Mar 2017 12:08:16 GMT</pubDate></item><item><title><![CDATA[Reply to Regular expression to find two words in files in folder on Sat, 25 Mar 2017 08:21:45 GMT]]></title><description><![CDATA[<p dir="auto">Does <code>(Word1)(?s:.*?)(word2)|(word2)(?s:.*?)(Word1)</code> work?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23030</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23030</guid><dc:creator><![CDATA[Per Isakson]]></dc:creator><pubDate>Sat, 25 Mar 2017 08:21:45 GMT</pubDate></item></channel></rss>