<?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 paragraph of X words containing multiple keywords ?]]></title><description><![CDATA[<p dir="auto">Hey there. I was looking on the web for a way to search through a PDF with more advanced researches than simply CTRL+F and 1 keyword.<br />
I tried acrobat reader, but  boolean and proximity researches, while being very close to what I need, aren’t exactly what I aim for.<br />
My idea is to give some keywords ( example: dog, cat, rabbit ), and then give a size for the paragraph in words ( example 500 words )<br />
The program would then search through all the PDF and find all paragraphs of  said quantity of words, containing the given keywords. In this case, 500 words long paragraph containing dog, cat and rabbit.</p>
<p dir="auto">I got told it can be done with notepad++, even if I have to convert the pdf to txt that’s not a problem. But I have no idea of what expression I have to use.<br />
Would you mind helping?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/21019/find-paragraph-of-x-words-containing-multiple-keywords</link><generator>RSS for Node</generator><lastBuildDate>Fri, 09 Oct 2026 13:46:54 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/21019.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 12 Apr 2021 21:09:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 19:05:50 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/n_antiyou" aria-label="Profile: n_antiyou">@<bdi>n_antiyou</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">As I said in my <strong>previous</strong> post, you may <strong>mix</strong> some styles, from the <strong><code>5</code></strong> styles, available by <strong>default</strong>, to get <strong>other</strong> colors, in order to color all your <strong>keywords</strong> !</p>
<p dir="auto">Refer to this post by <a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-Frank">@<bdi>Claudia-Frank</bdi></a>, who, unfortunately, is <strong>no</strong> longer <strong>active</strong> on this forum ! Her contribution was quite <strong>important</strong> and she provided quantity of <strong>excellent</strong> <strong><code>Python</code></strong> scripts, too ! Let’s wish her the <strong>best</strong> and good <strong>coding</strong> moments ;-))</p>
<p dir="auto"><a href="https://community.notepad-plus-plus.org/post/27621">https://community.notepad-plus-plus.org/post/27621</a></p>
<hr />
<p dir="auto">With the help of the <strong><code>NppQCP</code></strong> plugin ( <em>Quick Color Plugin</em> ), I built up a <strong><code>Word</code></strong> image which recapitulates the <strong>main</strong> style <strong>combinations</strong>, with <strong>significant</strong> colors and their <strong><code>RGB</code></strong> <strong>coordinates</strong></p>
<hr />
<p dir="auto"><img src="/assets/uploads/files/1618340486710-3a6919c6-acd7-4a43-80fe-b56305397952-image.png" alt="3a6919c6-acd7-4a43-80fe-b56305397952-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64932</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64932</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 13 Apr 2021 19:05:50 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 15:59:00 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/n_antiyou" aria-label="Profile: n_antiyou">@<bdi>n_antiyou</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: peterjones">@<bdi>peterjones</bdi></a>, <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"><a class="plugin-mentions-user plugin-mentions-a" href="/user/n_antiyou" aria-label="Profile: n_antiyou">@<bdi>n_antiyou</bdi></a>,</p>
<p dir="auto">For <strong><code>6</code></strong> keywords, you can use that <strong>mono</strong>-line regex , below, in <strong>free-spacing</strong> mode, which enables you to place any <strong>space</strong> within this <strong>long</strong> regex for a <strong>better</strong> readability !</p>
<p dir="auto">SEARCH / MARK <strong><code>(?xs-i)  (?=(\W+ \w+){0,299} \W+ Word_1)  (?=(?1){0,299} \W+ Word_2)  (?=(?1){0,299} \W+ Word_3)  (?=(?1){0,299} \W+ Word_4)  (?=(?1){0,299} \W+ Word_5)  (?=(?1){0,299} \W+ Word_6)  (?1){300}</code></strong></p>
<hr />
<p dir="auto">Now, you may use the <strong><code>Search &gt; Mark All &gt; Using #th style</code></strong> in order to highlight your <strong>keywords</strong> with a <strong>specific</strong> color. Note that, for your <strong><code>6th</code></strong> keyword, you’ll have to <strong>cheat</strong> a bit by applying <strong>two</strong> successive highlightings to the <strong>same</strong> word ! Just try to mix <strong>two</strong> styles ;-))</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
<p dir="auto"><strong>P.S.</strong> :</p>
<p dir="auto">Note that the syntax <strong><code>(\W+ \w+)</code></strong>, near the <strong>beginning</strong> of the regex, defines the <strong>group</strong> <strong><code>1</code></strong> containing the sub-regex <strong><code>\W+\w+</code></strong>, which is <strong>re-used</strong>, further on, thanks to the <strong>simple</strong> syntax <strong><code>(?1)</code></strong></p>
<p dir="auto">You’ll find some <strong>links</strong> to <strong>improve</strong> yourself in regexes <a href="https://community.notepad-plus-plus.org/topic/15765/faq-desk-where-to-find-regular-expressions-regex-documentation" title="Regex Docum"> here</a> !</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64922</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64922</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 13 Apr 2021 15:59:00 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 15:20:04 GMT]]></title><description><![CDATA[<p dir="auto">There might be, there’s people that do all sorts of things on fiverr it seems. XD</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64921</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64921</guid><dc:creator><![CDATA[n_antiyou]]></dc:creator><pubDate>Tue, 13 Apr 2021 15:20:04 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 15:17:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/n_antiyou" aria-label="Profile: n_antiyou">@<bdi>n_antiyou</bdi></a> said in <a href="/post/64918">Find paragraph of X words containing multiple keywords ?</a>:</p>
<blockquote>
<p dir="auto">Aren’t there programs that do this kind of research with a friendly UI?</p>
</blockquote>
<p dir="auto">Are there?  I guess you’d have to go and find them then.</p>
<blockquote>
<p dir="auto">Maybe I could find people on fiverr to develop an extention of google chrome that does this kind of research, so that it would also work on a PDF without converting to txt alltogether.</p>
</blockquote>
<p dir="auto">Are there people standing by just to do this sort of thing?<br />
That’s nice if so.<br />
Maybe they can field some of the oddball need regex questions we get asked here.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64920</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64920</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 13 Apr 2021 15:17:18 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 15:16:26 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/n_antiyou" aria-label="Profile: n_antiyou">@<bdi>n_antiyou</bdi></a>,</p>
<p dir="auto">Give me some <strong>minutes</strong> ! your <strong>last</strong> regex can be <strong>simplified</strong> ;-))</p>
<p dir="auto">BR</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64919</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64919</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 13 Apr 2021 15:16:26 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 15:11:53 GMT]]></title><description><![CDATA[<p dir="auto">Perfect, so assuming 6 keywords and 300 words as size, it should look like this:</p>
<p dir="auto">(?s-i)(?=(\W+\w+){0,299}\W+word1)(?=(\W+\w+){0,299}\W+word2)(?=(\W+\w+){0,299}\W+word3)(?=(\W+\w+){0,299}\W+word4)(?=(\W+\w+){0,299}\W+word5)(?=(\W+\w+){0,299}\W+word6)(?1){300}</p>
<p dir="auto">Correct?</p>
<p dir="auto">I’m starting to think this is a bit too complex tho. Not the expression per se, since once I understand how it works I can make new ones on my own, but the process takes time. Aren’t there programs that do this kind of research with a friendly UI?<br />
Maybe I could find people on fiverr to develop an extention of google chrome that does this  kind of research, so that it would also work on a PDF without converting to txt alltogether.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64918</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64918</guid><dc:creator><![CDATA[n_antiyou]]></dc:creator><pubDate>Tue, 13 Apr 2021 15:11:53 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 15:04:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/n_antiyou" aria-label="Profile: n_antiyou">@<bdi>n_antiyou</bdi></a></p>
<ol>
<li>Yep, that’s right.</li>
<li>each one of the <code>(?=(\W+\w+){0,49}\W+guidato)</code> terms applies to one of your required words.  You’ll notice right now, there are three of those terms, each with one of your required words.  You just need to add more of the same terms but with the new words.</li>
<li>with a different color? not in the same regular expression, sorry</li>
</ol>
]]></description><link>https://community.notepad-plus-plus.org/post/64917</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64917</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 13 Apr 2021 15:04:16 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 15:03:22 GMT]]></title><description><![CDATA[<p dir="auto">Oh, and one more ( sorry )</p>
<p dir="auto"><strong>3</strong> ) I see that notepad, when entering the expression and hitting "find ", it brings me to the proper place where the portion of the text is, and then enlightens it in grey. Is there a way to make so it also englithens the 3 keywords INSIDE, with a different color? ( any color, even the same color for all 3 keywords )<br />
You may look at the picture I sent above as an example.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64916</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64916</guid><dc:creator><![CDATA[n_antiyou]]></dc:creator><pubDate>Tue, 13 Apr 2021 15:03:22 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 14:58:25 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>  This is it! It works! Ahahah</p>
<p dir="auto">I am not sure if I did correct. To be honest, I have understood about 10% of what you guys wrote. But I copied</p>
<p dir="auto">(?s-i)(?=(\W+\w+){0,29}\W+DOG)(?=(?1){0,29}\W+CAT)(?=(?1){0,29}\W+RABBIT)(?1){30}</p>
<p dir="auto">substituing DOG/RABBIT/CAT with 3 other keywords, and notepad++ found a portion of the text 30 words long containing all 3.</p>
<p dir="auto">This is exactly what I was looking for.</p>
<p dir="auto">Now, I have only 2 questions left:</p>
<p dir="auto"><strong>1</strong>) If I want to modify the size of the portion of the text I want to find ( lets say from 30 to 50 ), would it look like this:</p>
<p dir="auto">"     (?s-i)(?=(\W+\w+){0,49}\W+guidato)(?=(?1){0,49}\W+parte)(?=(?1){0,49}\W+contributi)(?1){50}   "     ?</p>
<p dir="auto"><strong>2</strong> ) What is the expression to achieve the same result, but with 4 and 5 keywords instead of 3?   ( I know I could just ask what’s the pattern to follow to add more keywords… if you want you can write it down… I am scared that I won’t understand it tho )</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64915</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64915</guid><dc:creator><![CDATA[n_antiyou]]></dc:creator><pubDate>Tue, 13 Apr 2021 14:58:25 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 14:44:34 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 clarifications.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64914</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64914</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 13 Apr 2021 14:44:34 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 14:25:05 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/n_antiyou" aria-label="Profile: n_antiyou">@<bdi>n_antiyou</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: peterjones">@<bdi>peterjones</bdi></a>, <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">Ah… Yes, <strong>Alan</strong>, you’re right about the <strong><code>¤</code></strong> character ! So I repost <strong>all</strong> my previous reply, for a <strong>better</strong> understanding and to provide <strong>new</strong> versions of the regexes !</p>
<hr />
<p dir="auto">Unlike <a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: peterjones">@<bdi>peterjones</bdi></a>, I will consider a <strong>continuous</strong> range of <strong>any</strong> character, even the <strong>EOL</strong> chars, using the <strong><code>(?s)</code></strong> modifier.</p>
<p dir="auto">Now, we can <strong>associate</strong> any <strong>common</strong> word with its <em>leading</em> <strong>non-word</strong> char(s), whatever they are, even <strong>line-break(s)</strong>. Therefore, it can be expressed with the regex <strong><code>\W+\w+</code></strong>, which stands for a <strong>non-null</strong> range of <strong>non-word</strong> chars followed by a <strong>non-null</strong> range of <strong>word</strong> chars</p>
<p dir="auto">Then, in order to match a <strong>block</strong> of <strong><code>N</code></strong> words containing the words <strong>Word_1</strong> <em>and</em> <strong>Word_2</strong> <em>and</em> <strong>Word_3</strong>, at least <strong>once</strong> each, use the <strong>generic</strong> regex, below, written with the <strong>free-spacing</strong> and <strong>multi</strong>-lines mode <strong><code>(?x)</code></strong></p>
<p dir="auto"><strong>Remember</strong> that, in this mode :</p>
<ul>
<li>
<p dir="auto">A <strong>space</strong> char is <strong>not</strong> taken in account and must be coded as <strong><code>\x20</code></strong> or <strong>preceded</strong> by a <strong><code>\</code></strong> character )</p>
</li>
<li>
<p dir="auto">Any text, after a <strong>first</strong> <strong><code>#</code></strong> character, is <strong>not</strong> taken in account, too and is <strong>only</strong> comments !</p>
</li>
<li>
<p dir="auto">To match a <strong>literal</strong> <strong><code>#</code></strong> char, use, either, the <strong><code>\x23</code></strong> or <strong><code>\#</code></strong> syntax !</p>
</li>
</ul>
<pre><code class="language-z">(?xs-i)
(?= ( \W+ \w+ ) {0,N-1} \W+ Word_1 )
(?=    (?1)     {0,N-1} \W+ Word_2 )
(?=    (?1)     {0,N-1} \W+ Word_3 )
       (?1)     {N}
</code></pre>
<p dir="auto">So, if I take up your example, where <strong><code>N = 30</code></strong> words, <strong>without</strong> using the <strong>free-spacing</strong> mode :</p>
<ul>
<li>
<p dir="auto">Open the <strong>Search</strong> dialog ( <strong><code>Ctrl + F</code></strong> )</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?s-i)(?=(\W+\w+){0,29}\W+DOG)(?=(?1){0,29}\W+CAT)(?=(?1){0,29}\W+RABBIT)(?1){30}</code></strong>    Regex <strong><code>A</code></strong></p>
</li>
<li>
<p dir="auto"><strong>Tick</strong> the <strong><code>Wrap around</code></strong> option</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>Find next</code></strong> button</p>
</li>
</ul>
</li>
</ul>
<p dir="auto">You may <strong>test</strong> that regex expression against the <strong>sample</strong> text, below :</p>
<p dir="auto">Note, <strong>Alan</strong> that this regex <strong><code>A</code></strong> selects <strong>all</strong> the block and <strong>not</strong> each keyword, <strong>individually</strong> !</p>
<pre><code class="language-diff">word word word word word word word word word DOG
word word word word word word word word word DOG
word word word word word word word word word word

word word word word word word word word word CAT
word word word word word word word word word CAT
word word word word word word word word word word

word word word word word word word word word RABBIT
word word word word word word word word word RABBIT
word word word word word word word word word word

word word word word word word word word word DOG
word word word word word word word word word CAT
word word word word word word word word word RABBIT

DOG word word word word word word word word word
CAT word word word word word word word word word
RABBIT word word word word word word word word word

word word word RABBIT word word word word word word
word DOG word word word word word word word word
word word word word word word word word CAT word

RABBIT word word word word word DOG word word word
word DOG word word word word CAT word word word
word CAT word word word word word word word RABBIT

word word word word word word word word word word
word word word word word word word word word word
word word word word word word word  CAT DOG RABBIT

DOG RABBIT CAT word word word word word word word
word word word word word word word word word word
word word word word word word word word word word

word word word word word word word word word word
word word word word word word word word word DOG
word word word word word word word word word DOG

word word word word word word word word word word
word word word word word word word word word CAT
word word word word word word word word word CAT

word word word word word word word word word word
word word word word word word word word word RABBIT
word word word word word word word word word RABBIT

word word word word word word word word word word
</code></pre>
<hr />
<p dir="auto">Now, if you want to match, <strong>individually</strong>, each word <strong><code>DOG</code></strong>, <strong><code>CAT</code></strong> or <strong><code>RABBIT</code></strong>, of these blocks, we need a <strong>temporary</strong> character, not <strong>existing</strong> yet,  in <strong>current</strong> file, which will be located at the <strong>end</strong> of these blocks</p>
<p dir="auto">By that means, we’ll be <strong>sure</strong> that the range, between any <strong>found</strong> occurrence of <strong><code>CAT</code></strong>, <strong><code>DOG</code></strong> or <strong><code>RABBIT</code></strong> <strong>included</strong> and this <strong>ending</strong> anchor, will <strong>not</strong> exceed <strong><code>30</code></strong> words !</p>
<p dir="auto">I chose the <strong><code>¤</code></strong> character as the <strong>anchor</strong>, but any <strong>single</strong> char, <strong>not</strong> regex <strong>meta</strong>-character, would be <strong>OK</strong>, too</p>
<ul>
<li>
<p dir="auto">Open the <strong>Replace</strong> dialog ( <strong><code>Ctrl + H</code></strong> )</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?s-i)(?=(\W+\w+){0,29}\W+DOG)(?=(?1){0,29}\W+CAT)(?=(?1){0,29}\W+RABBIT)(?1){30}\K</code></strong>    Regex <strong><code>B</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>¤</code></strong>   ( the <strong>anchor</strong> )</p>
</li>
<li>
<p dir="auto"><strong>Tick</strong> the <strong><code>Wrap around</code></strong> option</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>Replace All</code></strong> button ( Do <strong>not</strong> use the <strong><code>Replace</code></strong> button )</p>
</li>
</ul>
</li>
</ul>
<p dir="auto">You should get this <strong>output</strong> :</p>
<pre><code class="language-diff">word word word word word word word word word DOG
word word word word word word word word word DOG
word word word word word word word word word word

word word word word word word word word word CAT
word word word word word word word word word CAT
word word word word word word word word word word

word word word word word word word word word RABBIT
word word word word word word word word word RABBIT
word word word word word word word word word word

word word word word word word word word word DOG
word word word word word word word word word CAT
word word word word word word word word word RABBIT¤

DOG word word word word word word word word word
CAT word word word word word word word word word
RABBIT word word word word word word word word word¤

word word word RABBIT word word word word word word
word DOG word word word word word word word word
word word word word word word word word CAT word¤

RABBIT word word word word word DOG word word word
word DOG word word word word CAT word word word
word CAT word word word word word word word RABBIT¤

word word word word word word word word word word
word word word word word word word word word word
word word word word word word word  CAT DOG RABBIT¤

DOG RABBIT CAT word word word word word word word
word word word word word word word word word word
word word word word word word word word word word¤

word word word word word word word word word word
word word word word word word word word word DOG
word word word word word word word word word DOG

word word word word word word word word word word
word word word word word word word word word CAT
word word word word word word word word word CAT

word word word word word word word word word word
word word word word word word word word word RABBIT
word word word word word word word word word RABBIT

word word word word word word word word word word
</code></pre>
<hr />
<p dir="auto">Then, against this <strong>modified</strong> text, above, the <strong>search</strong> or <strong>marking</strong> of any word <strong><code>DOG</code></strong>, <strong><code>CAT</code></strong> or <strong><code>RABBIT</code></strong>, <strong>within</strong> the concerned <strong>sections</strong>, can be performed with the regex :</p>
<p dir="auto">SEARCH / MARK <strong><code>(?-i)(DOG|CAT|RABBIT)(?=(\W+\w+){0,29}¤)</code></strong>    Regex <strong><code>C</code></strong></p>
<p dir="auto"><strong>Alan</strong>, this time, any <strong>keyword</strong>, inside the <strong>concerned</strong> blocks, are <strong>individually</strong> matched with the regex <strong><code>C</code></strong> ! Note that if you would have <strong>removed</strong> the <strong>anchor</strong> <strong><code>¤</code></strong> at the <strong>end</strong> of the look-ahead, the regex engine would have found <strong>absolutely all</strong> the occurrences of the <strong>keywords</strong> <strong><code>DOG</code></strong>, <strong><code>CAT</code></strong> or <strong><code>RABBIT</code></strong> ! Not what we expect to ! Hence, the necessity of the <strong>anchor</strong> ;-))</p>
<hr />
<p dir="auto">Finally, in order to <strong>delete</strong> the <strong>temporary</strong> <strong><code>¤</code></strong> character, use this <strong>trivial</strong> regex :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>¤</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
</li>
</ul>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64910</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64910</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 13 Apr 2021 14:25:05 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 12:14:28 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">Nice techniques, here.</p>
<p dir="auto">Some notes:</p>
<blockquote>
<p dir="auto">You may test that regex expression against the sample text below :</p>
</blockquote>
<p dir="auto">It appears this text already has the ¤ character in it??</p>
<blockquote>
<p dir="auto">Select all text from (?xs-i) till ( \W+ \w+ ) {30}</p>
</blockquote>
<p dir="auto">It is a bit awkward to have to copy the regex specified on this site into a Notepad++ tab, and then select it again in order to press Ctrl+f on it.<br />
Suggest in the future to also provide in postings here a directly copyable version of the regex (meaning, a non <code>(?x)</code> version).  Just a suggestion to avoid “losing” the newbies.</p>
<blockquote>
<p dir="auto">Now, if you want to match each word DOG, CAT or RABBIT, in these blocks, only, we’ll need to temporary add a character, not existing yet, in current file, at the end of these blocks</p>
</blockquote>
<p dir="auto">At first I thought this solution would match if only one of the 3 words were present (because of the use of “or”) but in reality it only matches if all 3 are present (an “and” search).<br />
As the “and” scenario was considered in the earlier half of the previous posting, I’m confused as to what this second half is showing…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64907</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64907</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 13 Apr 2021 12:14:28 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 14:31:13 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/n_antiyou" aria-label="Profile: n_antiyou">@<bdi>n_antiyou</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>
<h4>Please, just skip to my <strong>next</strong> post, below. This one is now <strong>out of date</strong> !</h4>
<p dir="auto">Unlike <a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: peterjones">@<bdi>peterjones</bdi></a>, I will consider a <strong>continuous</strong> range of <strong>any</strong> character. So a <strong>single</strong> common word can be defined by the regex <strong><code>\W+\w+</code></strong>, which stands for a <strong>non-null</strong> range of <strong>non-word</strong> chars followed by a <strong>non-null</strong> range of <strong>word</strong> chars</p>
<p dir="auto">Now in order to match a <strong>block</strong> of <strong><code>N</code></strong> words containing the words <strong>Word_1</strong> <em>and</em> <strong>Word_2</strong> <em>and</em> <strong>Word_3</strong>, use the following regex, written with the <strong>free-spacing</strong> and <strong>multi</strong>-lines mode ( In this mode, a <strong>space</strong> char is <strong>not</strong> taken in account and must be coded as <strong><code>\x20</code></strong> or <strong>preceded</strong> by a <strong><code>\</code></strong> character</p>
<pre><code class="language-z">(?xs-i)
(?= ( \W+ \w+ ) {0,N-1} \W+ Word_1 )
(?= ( \W+ \w+ ) {0,N-1} \W+ Word_2 )
(?= ( \W+ \w+ ) {0,N-1} \W+ Word_3 )
( \W+ \w+ ) {N}
</code></pre>
<p dir="auto">So, if I take up your example, with a range of <strong><code>30</code></strong> words, we get the <strong>effective</strong> search regex :</p>
<pre><code class="language-z">(?xs-i)
(?= ( \W+ \w+ ) {0,29} \W+ DOG    )
(?= ( \W+ \w+ ) {0,29} \W+ CAT    )
(?= ( \W+ \w+ ) {0,29} \W+ RABBIT )
( \W+ \w+ ) {30}
</code></pre>
<ul>
<li>
<p dir="auto">Select <strong>all</strong> text from <strong><code>(?xs-i)</code></strong> till <strong><code>( \W+ \w+ ) {30}</code></strong></p>
</li>
<li>
<p dir="auto">Open the <strong>Search</strong> dialog ( <strong><code>Ctrl + F</code></strong> )</p>
<ul>
<li>
<p dir="auto"><strong>Tick</strong> the <strong><code>Wrap around</code></strong> option</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>Find next</code></strong> button</p>
</li>
</ul>
</li>
</ul>
<p dir="auto">You may <strong>test</strong> that regex expression against the <strong>sample</strong> text below :</p>
<pre><code class="language-diff">word word word word word word word word word DOG
word word word word word word word word word DOG
word word word word word word word word word word

word word word word word word word word word CAT
word word word word word word word word word CAT
word word word word word word word word word word

word word word word word word word word word RABBIT
word word word word word word word word word RABBIT
word word word word word word word word word word

word word word word word word word word word DOG
word word word word word word word word word CAT
word word word word word word word word word RABBIT¤

DOG word word word word word word word word word
CAT word word word word word word word word word
RABBIT word word word word word word word word word¤

word word word RABBIT word word word word word word
word DOG word word word word word word word word
word word word word word word word word CAT word¤

RABBIT word word word word word DOG word word word
word DOG word word word word CAT word word word
word CAT word word word word word word word RABBIT¤

word word word word word word word word word word
word word word word word word word word word word
word word word word word word word  CAT DOG RABBIT¤

DOG RABBIT CAT word word word word word word word
word word word word word word word word word word
word word word word word word word word word word¤

word word word word word word word word word word
word word word word word word word word word DOG
word word word word word word word word word DOG

word word word word word word word word word word
word word word word word word word word word CAT
word word word word word word word word word CAT

word word word word word word word word word word
word word word word word word word word word RABBIT
word word word word word word word word word RABBIT

word word word word word word word word word word
</code></pre>
<hr />
<p dir="auto">Now, if you want to match <strong>each</strong> word <strong><code>DOG</code></strong>, <strong><code>CAT</code></strong> or <strong><code>RABBIT</code></strong>, in these blocks, <strong>only</strong>, we’ll need to <strong>temporary</strong> add a character, not <strong>existing</strong> yet,  in <strong>current</strong> file, at the <strong>end</strong> of these blocks</p>
<p dir="auto">In the following S/R, below, I chose the <strong><code>¤</code></strong> character. So :</p>
<ul>
<li>Select <strong>all</strong> the text, below :</li>
</ul>
<pre><code class="language-z">(?xs-i)
(?= ( \W+ \w+ ) {0,29} \W+ DOG    )
(?= ( \W+ \w+ ) {0,29} \W+ CAT    )
(?= ( \W+ \w+ ) {0,29} \W+ RABBIT )
( \W+ \w+ ) {30} \K
</code></pre>
<ul>
<li>
<p dir="auto">Open the <strong>Replace</strong> dialog ( <strong><code>Ctrl + H</code></strong> )</p>
<ul>
<li>
<p dir="auto">Type in <strong><code>¤</code></strong> in the <strong><code>Replace with:</code></strong> zone</p>
</li>
<li>
<p dir="auto"><strong>Tick</strong> the <strong><code>Wrap around</code></strong> option</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>Replace All</code></strong> button ( Do <strong>not</strong> use the <strong><code>Replace</code></strong> button )</p>
</li>
</ul>
</li>
</ul>
<hr />
<p dir="auto">Then, <strong>search</strong> or <strong>marking</strong> should be <strong>easy</strong> with the regex :</p>
<p dir="auto">SEARCH / MARK <strong><code>(?-i)(DOG|CAT|RABBIT)(?=(\W+\w+){0,29}¤)</code></strong></p>
<hr />
<p dir="auto">Finally, in order to <strong>delete</strong> the <strong>temporary</strong> <strong><code>¤</code></strong> character, use this <strong>trivial</strong> regex :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>¤</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
</li>
</ul>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64897</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64897</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 13 Apr 2021 14:31:13 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Tue, 13 Apr 2021 01:04:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/n_antiyou" aria-label="Profile: n_antiyou">@<bdi>n_antiyou</bdi></a></p>
<p dir="auto">You seem to be wanting to find multiple words within some proximity of each other?  Here’s an example of something I used to find TWO words within so many characters of each other: <a href="https://community.notepad-plus-plus.org/post/60219">https://community.notepad-plus-plus.org/post/60219</a></p>
<p dir="auto">Maybe that general idea could be extended to more words.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64895</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64895</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 13 Apr 2021 01:04:51 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Mon, 12 Apr 2021 22:37:46 GMT]]></title><description><![CDATA[<p dir="auto">An english native speaker friend of mine suggests I should call it " a portion " or " a section " of the text. Since Paragraph have a precise punctuation and I don’t care about the punctuation.<br />
I am just basically interested in finding a precise portion of a text based on size and keywords. Again, sorry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64892</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64892</guid><dc:creator><![CDATA[n_antiyou]]></dc:creator><pubDate>Mon, 12 Apr 2021 22:37:46 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Mon, 12 Apr 2021 22:23:51 GMT]]></title><description><![CDATA[<p dir="auto">As of dots, comas and stuff like that, I don’t care. The paragraph could even be:</p>
<p dir="auto">,word word word. Word word word. Word. word word CAT.<br />
Word, DOG, word. Word. Word. Word word word word word,<br />
word word word word word RABBIT word word word. word wor</p>
<p dir="auto">Another example that makes it easy to understand is this:<br />
Imagine I have a book in PDF that talks about doctors A and B. Doctor B discovers a new research method called C.<br />
Now, A/B/C will be named numerous times in the PDF, across thousands of pages.</p>
<p dir="auto">But lets assume I want to find the portion of the text where A talks about what he thinks of B and C, then the only option is a script similar to what I am looking for.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64891</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64891</guid><dc:creator><![CDATA[n_antiyou]]></dc:creator><pubDate>Mon, 12 Apr 2021 22:23:51 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Mon, 12 Apr 2021 22:17:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a><br />
First of all excuse me for making 3 posts in a row. I’m kinda new here.<br />
I made a picture in the hope to better explain what I need: <img src="/assets/uploads/files/1618265629475-fadfadsfasdfasdfasdf.png" alt="fadfadsfasdfasdfasdf.png" class=" img-fluid img-markdown" /><br />
This is a sample text, each line is 10 words, but I am telling this only to help us keep count of how many words there are. I don’t care about the lines per se.<br />
Now, I want the program to find a portion/paragraph of this text that is 30 words big and contains CAT, DOG and RABBIT.</p>
<p dir="auto">As you can see I enlightened a portion of the text where this event happens.<br />
The program should  NOT pick lines such as the first 3:</p>
<p dir="auto">word word word word word word word word word DOG<br />
word word word word word word word word word DOG<br />
word word word word word word word word word word</p>
<p dir="auto">Because it only contains DOG, but doesn’t contain CAT or RABBIT.</p>
<p dir="auto">Is this easier to understand?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64890</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64890</guid><dc:creator><![CDATA[n_antiyou]]></dc:creator><pubDate>Mon, 12 Apr 2021 22:17:49 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Mon, 12 Apr 2021 22:16:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/n_antiyou" aria-label="Profile: n_antiyou">@<bdi>n_antiyou</bdi></a></p>
<blockquote>
<p dir="auto">For paragraph, I do not mean one line of text. I mean a portion of the text.</p>
</blockquote>
<p dir="auto">You still haven’t really defined what a paragraph is (to you).<br />
A common (but not necessarily strict) definition is a section of text terminated by two (or maybe more) consecutive line-ending characters.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64889</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64889</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 12 Apr 2021 22:16:25 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Mon, 12 Apr 2021 21:44:47 GMT]]></title><description><![CDATA[<p dir="auto">I tried your expression and it seems to work fine ( besides the fact it counts “paragraph” as a line ), but it only checks for 1 of the 3 keywords. I want it to find a paragraph that contains all 3 words, not just one.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64888</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64888</guid><dc:creator><![CDATA[n_antiyou]]></dc:creator><pubDate>Mon, 12 Apr 2021 21:44:47 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Mon, 12 Apr 2021 21:33:09 GMT]]></title><description><![CDATA[<p dir="auto">Oh, sorry for missing what I mean with paragraph. Might be a language barrier as english is not my main language. For paragraph, I do not mean one line of text. I mean a portion of the text.  So if a page  contains 30 lines of text and 3000 words, a paragraph of 500 words is just a piece of that page.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64887</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64887</guid><dc:creator><![CDATA[n_antiyou]]></dc:creator><pubDate>Mon, 12 Apr 2021 21:33:09 GMT</pubDate></item><item><title><![CDATA[Reply to Find paragraph of X words containing multiple keywords ? on Mon, 12 Apr 2021 21:29:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/n_antiyou" aria-label="Profile: n_antiyou">@<bdi>n_antiyou</bdi></a> ,</p>
<p dir="auto">Well, you would definitely have to convert the PDF to txt, because Notepad++ is a text editor, and doesn’t understand PDF binary format.</p>
<p dir="auto">To search for any of dog,cat,rabbit, you would use the search dialog in regular expression mode, <code>(dog|cat|rabbit)</code> as the search string.</p>
<p dir="auto">However, you were saying something about “size of paragraph” and “quantity of said words”.  I’m not sure there’s any good way to do what you want in regular expressions. In a programming language, you could easily define restrictions like that.  In regex, you might be able to work something out.</p>
<p dir="auto">For example, with the text</p>
<pre><code>this paragraph is a short dog

this paragraph has more words and matches cat

too short rabbit

this paragraph has enough words and but doesn't have canines, felines, or bugs bunny

this paragraph has more words and dog matches 

this paragraph has more words and rabbit matches 
</code></pre>
<p dir="auto">There are three paragraphs that match, where “paragraph” is defined as a line of text that ends with a newline sequence.  I used the restriction that the paragraph had to contain 7 or more words to match.  If you wanted “500”, just change the 7 to 500.</p>
<ul>
<li>FIND = <code>(?-s)^(?=.*(dog|cat|rabbit))(\S+\h+){7,}.*$</code><br />
SEARCH MODE = regular expression</li>
</ul>
<p dir="auto">This says "turn off <code>. matches newline</code>, start the match at the beginning of the line; the line must contain dog, cat, or rabbit somewhere.  The line must also contain 7 or more “words”, where a word is defined as one or more non-whitespace characters followed by at least one horizontal space (space or tab).</p>
<p dir="auto">If your paragraph rule is really that a paragraph might contain newlines, and that paragraph breaks are when there are two newlines in a row, the search expression would have to change.</p>
<p dir="auto">If you want a better answer than that, you’ll have to ask a more-detailed question.</p>
<p dir="auto">-—</p>
<p dir="auto"><em>Do you want regex search/replace help?  Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you.  All example text should be marked as literal text using the <code>&lt;/&gt;</code> toolbar button or manual <a href="https://community.notepad-plus-plus.org/topic/14262/how-to-markdown-code-on-this-forum/4">Markdown syntax</a>. To make <code>regex in red</code> (and so they keep their special characters like *), use backticks, like <code>`^.*?blah.*?\z`</code>. Screenshots can be pasted from the clipboard to your post using <code>Ctrl+V</code> to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have <strong>and</strong> the text you want to get from that data; include examples of things that <strong>should match</strong> and be transformed, <strong>and</strong> things that <strong>don’t match</strong> and should be left alone; show <strong>edge cases</strong> and make sure you examples are as <strong>varied</strong> as your real data.  Show the regex you already tried, <strong>and why</strong> you thought it should work; tell us what’s wrong with what you <strong>do</strong> get. Read the official <a href="https://npp-user-manual.org/docs/searching/#regular-expressions" rel="nofollow ugc">NPP Searching / Regex docs</a> and the forum’s <a href="https://community.notepad-plus-plus.org/topic/15765/faq-desk-where-to-find-regex-documentation">Regular Expression FAQ</a>. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.</em></p>
<p dir="auto">-----</p>
<p dir="auto">see also <a href="/topic/16178">“FAQ Desk: Why Does My .docx File Look Like Junk In Notepad++”</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/64886</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64886</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 12 Apr 2021 21:29:16 GMT</pubDate></item></channel></rss>