<?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[Regex: Find this 3 words within the range of 8 words]]></title><description><![CDATA[<p dir="auto">For example, like this google search: <code>"mother * beautiful * car"</code> With this search, on google I find this line:</p>
<p dir="auto">Text messages haunt mother after ‘beautiful’ daughter’s car crash death.</p>
<p dir="auto">The same, I want to use a regex to find the same line. So I have to find this 3 words within the range of 8 words</p>
<p dir="auto">I made this regex, but not to good:</p>
<p dir="auto"><code>( mother)\h+(\w+\h+){1,8}?(beautiful )</code> #this will search <code>mother</code> and <code>beautiful</code> between 8 words. This is ok. Works.</p>
<p dir="auto">but to search 3 words, between 8 words, it is difficult:</p>
<p dir="auto"><code>( MOTHER)\h+(\w+\h+){1,8}?(BEAUTIFUL )|\h+(\w+\h+){1,8}?(CAR)</code></p>
<p dir="auto">anyone can help me?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/20900/regex-find-this-3-words-within-the-range-of-8-words</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 12:41:33 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/20900.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 17 Mar 2021 17:35:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regex: Find this 3 words within the range of 8 words on Tue, 11 May 2021 17:40:36 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>, wow. This is some next-level regexing from my point of view. You need a tip jar for that kind of work!</p>
<p dir="auto">Actually, now that I think of it, regex-for-hire might be a useful thing.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/65895</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/65895</guid><dc:creator><![CDATA[pbarney]]></dc:creator><pubDate>Tue, 11 May 2021 17:40:36 GMT</pubDate></item><item><title><![CDATA[Reply to Regex: Find this 3 words within the range of 8 words on Fri, 19 Mar 2021 07:39:08 GMT]]></title><description><![CDATA[<p dir="auto">Very nice this piece of regex <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> , extracted from one regex of your explanation:</p>
<p dir="auto"><code>([^\w\r\n]+)</code> - Select all the empty spaces and all the signs without words or numbers on each line</p>
<p dir="auto"><code>(.*?[^\w\r\n])</code> - Select everything on each line except the last word on each line</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64106</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64106</guid><dc:creator><![CDATA[Vasile Caraus]]></dc:creator><pubDate>Fri, 19 Mar 2021 07:39:08 GMT</pubDate></item><item><title><![CDATA[Reply to Regex: Find this 3 words within the range of 8 words on Thu, 18 Mar 2021 20:33:53 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>, <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"><strong>Vasile</strong>, forget <strong>everything</strong> about my <strong>previous</strong> attempt ! I was mistaken in <strong>many</strong> ways :-((</p>
<p dir="auto">So, I assume :</p>
<ul>
<li>
<p dir="auto"><strong>Three</strong> KEY-words ( <strong><code>you</code></strong> , <strong><code>to</code></strong> and <strong><code>and</code></strong> ) which must <strong>all</strong> be present, at least <strong>once</strong>, in <strong>current</strong> line</p>
</li>
<li>
<p dir="auto">The range to match must contain these <strong>three</strong> KEY-words in any <strong>order</strong></p>
</li>
<li>
<p dir="auto">The range, between the a <strong>first</strong> and <strong>last</strong> KEY-word, <strong>included</strong>, must <strong>not</strong> contain <strong>more</strong> than <strong><code>8</code></strong> words</p>
</li>
<li>
<p dir="auto">No KEY-word exists between the <strong>first</strong> and <strong>second</strong> KEY-words found NOR between the <strong>second</strong> and <strong>third</strong> KEY-words</p>
</li>
</ul>
<hr />
<p dir="auto">Here is the <strong>correct</strong> and <strong>definitive</strong> regex S/R, again, with the <strong>free-spacing</strong> mode !</p>
<pre><code class="language-z">(?xi-s)                                                                 # FREE-SPACING mode and search SENSITIVE to CASE and LIMITED to a SINGLE line, at a time 
(?=\b(you|to|and)[^\w\r\n]+(?:\w+[^\w\r\n]+){0,6}?(?!\1)(you|to|and)\b) # IF KEY_word_#1 + NON-WORD char(s) + [any WORD + NON-WORD char(s)] from 0 to 6 TIMES + KEY_word_#2, DIFFERENT from KEY_word_#1
(?=\b\1[^\w\r\n]+(?:\w+[^\w\r\n]+){0,6}?(?!\1|\2)(?1)\b)                # IF KEY_word_#1 + NON-WORD char(s) + [any WORD + NON-WORD char(s)] from 0 to 6 TIMES + KEY_word_#3, DIFFERENT from KEY_word_#1 and KEY_word_#2
\b\1[^\w\r\n]+                                                          # Whole KEY_word_#1 ( Stored as GROUP 1 ) + NON-WORD CHARS
(?:(?:(?!(?1)).)+?[^\w\r\n]+)?                                          # The SHORTEST POSSIBLE range of chars, NOT containing any KEY-words (?1) + NON-WORD char(s), till ...
(?!\1)(you|to|and)[^\w\r\n]+                                            # A whole KEY-word, DIFFERENT from KEY_word_#1 ( Stored as GROUP 2 ) + NON-WORD char(s)
(?:(?:(?!(?1)).)+?[^\w\r\n]+)?                                          # The SHORTEST POSSIBLE range of chars, NOT containing any KEY-words (?1) + NON-WORD char(s), till ...
(?!\1|\3)(?1)\b                                                         # A whole KEY-word, DIFFERENT from GROUP 1 ( KEY_word_#1 ) and GROUP 2 ( KEY_word_#2 )
</code></pre>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">You may change the <strong>maximum</strong> number of the <strong>lazy</strong> quantifiers <strong><code>{0,6}?</code></strong>, in the <strong>two</strong> locations, for instance, <strong><code>{0,12}?</code></strong>, in order to <strong>increase</strong> the <strong>length</strong> of the range in words</p>
</li>
<li>
<p dir="auto">Remark that, if you want a <strong>maximum</strong> of <strong><code>N</code></strong> words, between the <strong>first</strong> and the <strong>last</strong> KEY-word, you need to use the <strong><code>{0,N-2}?</code></strong> <strong>quantifier</strong>  !</p>
</li>
<li>
<p dir="auto">If you <strong>change</strong> some of the words, while <strong>still</strong> keeping <strong><code>3</code></strong> distinct words, replace the part <strong><code>you|to|and</code></strong> in <strong>three</strong> locations of that regex ( lines <strong><code>2</code></strong> and <strong><code>6</code></strong> )</p>
</li>
</ul>
<hr />
<p dir="auto">Now, in order to <strong>test</strong> it, as I did, :</p>
<ul>
<li>
<p dir="auto">Open the <strong><code>license.txt</code></strong> file</p>
</li>
<li>
<p dir="auto">Open the <strong>Find</strong> dialog ( <strong><code>Ctrl + F</code></strong> )</p>
<ul>
<li>
<p dir="auto">Select the <strong><code>Normal</code></strong> search mode</p>
</li>
<li>
<p dir="auto"><strong>Tick</strong> the <strong><code>Match whole word only</code></strong> option</p>
</li>
<li>
<p dir="auto"><strong>Untick</strong> the <strong><code>Match case</code></strong> option</p>
</li>
<li>
<p dir="auto">Close the <strong>Find</strong> dialog ( <strong><code>ESC</code></strong> )</p>
</li>
</ul>
</li>
<li>
<p dir="auto">Select any word <strong><code>you</code></strong></p>
</li>
<li>
<p dir="auto">Run the <strong><code>Search &gt; Mark All &gt; Using 1st Style</code></strong> command</p>
</li>
<li>
<p dir="auto">Select any word <strong><code>to</code></strong></p>
</li>
<li>
<p dir="auto">Run the <strong><code>Search &gt; Mark All &gt; Using 2nd Style</code></strong> command</p>
</li>
<li>
<p dir="auto">Select any word <strong><code>and</code></strong></p>
</li>
<li>
<p dir="auto">Run the <strong><code>Search &gt; Mark All &gt; Using 3rd Style</code></strong> command</p>
</li>
</ul>
<p dir="auto">Now, you can <strong>test</strong> the regex above against the <strong><code>license.txt</code></strong> file and try also with, for instance, the <strong>lazy</strong> quantifiers <strong><code>{0,9}?</code></strong> or <strong><code>{0,12}?</code></strong>, which, remember, must be changed in <strong>two</strong> locations of the regex !</p>
<p dir="auto"><em>REMINDER</em> :</p>
<ul>
<li>
<p dir="auto">Select all the regex from <strong><code>(?xi-s)</code></strong> to <strong><code>(?!\1|\3)(?1)\b</code></strong></p>
</li>
<li>
<p dir="auto">Open the <strong><code>Find</code></strong> dialog <strong><code>( Ctrl + F )</code></strong></p>
</li>
</ul>
<p dir="auto">=&gt; All this <strong>multi</strong>-lines text should be <strong>inserted</strong> in the <strong><code>Find what:</code></strong> field</p>
<hr />
<p dir="auto">Now, here is an <strong>other</strong> regex, much <strong>more simple</strong>, which can be used if your goal is to search <strong>two</strong> words <strong>only</strong>, in a <strong>maximum</strong> range of words !</p>
<p dir="auto">So, I assume :</p>
<ul>
<li>
<p dir="auto"><strong>Two</strong> KEY-words ( <strong><code>you</code></strong> and  <strong><code>and</code></strong> ) which must <strong>all</strong> be present, at least <strong>once</strong>, in <strong>current</strong> line</p>
</li>
<li>
<p dir="auto">The range to match must contain these <strong>two</strong> KEY-words in any <strong>order</strong></p>
</li>
<li>
<p dir="auto">The range, between the a <strong>first</strong> and <strong>last</strong> KEY-word, <strong>included</strong>, must <strong>not</strong> contain <strong>more</strong> than <strong><code>8</code></strong> words</p>
</li>
<li>
<p dir="auto">No KEY-word exists between the <strong>first</strong> and the <strong>last</strong> KEY-words found</p>
</li>
</ul>
<hr />
<p dir="auto">Here is this <strong>second</strong> regex S/R, using the <strong>free-spacing</strong> mode :</p>
<pre><code class="language-z">(?xi-s)                          # FREE-SPACING mode and search SENSITIVE to CASE and LIMITED to a SINGLE line, at a time 
\b(you|and)[^\w\r\n]+            # Whole KEY_word_#1 ( Stored as GROUP 1 ) + NON-WORD CHARS
(?:(?!(?1))\w+[^\w\r\n]+){0,6}?  # Any word, NOT containing any KEY-words (?1) + NON-WORD char(s), REPEATED between 0 and SIX times
(?!\1)(?1)\b                     # A whole KEY-word, DIFFERENT from GROUP 1 ( KEY_word_#1 )
</code></pre>
<p dir="auto">You may <strong>test</strong> this regex against the <strong><code>license.txt</code></strong> file and change either, the words in <strong><code>you|and</code></strong> and/or change the <strong>maximum</strong>, testing, for instance, the <strong><code>{0,9}?</code></strong> or <strong><code>{0,12}?</code></strong> values !</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64093</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64093</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 18 Mar 2021 20:33:53 GMT</pubDate></item><item><title><![CDATA[Reply to Regex: Find this 3 words within the range of 8 words on Thu, 18 Mar 2021 14:42:34 GMT]]></title><description><![CDATA[<p dir="auto">thanks <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/64084</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64084</guid><dc:creator><![CDATA[Vasile Caraus]]></dc:creator><pubDate>Thu, 18 Mar 2021 14:42:34 GMT</pubDate></item><item><title><![CDATA[Reply to Regex: Find this 3 words within the range of 8 words on Thu, 18 Mar 2021 13:24:51 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">You said :</p>
<blockquote>
<p dir="auto">Your regex (?=(mother|beautiful|car)\h(?:\w+\h){1,6}(?!\1)(mother|beautiful|car)) only puts the cursor, but is doesn’t make a select from WORD 1 to WORD 2 and WORD 3 (mother … beautiful … car)</p>
</blockquote>
<p dir="auto">But this is <strong>NOT</strong> my regex !!! Just <em>ONE</em> of the conditions of the <strong>overall</strong> regex in order to <strong>valid</strong> a match attempt which respects <strong>all</strong> the hypotheses !</p>
<p dir="auto">The <strong>EXACT</strong> regex is, indeed :</p>
<pre><code class="language-z">(?x)                                                                     # FREE-SPACING Mode 
(?i-s)                                                                   # Search SENSITIVE to CASE and LIMITED to a SINGLE line, at a time
(?=.*mother)(?=.*beautiful)(?=.*car)                                     # IF EACH KEY word exists, further on, at least ONCE, in CURRENT line
.*?\K                                                                    #   LEADING chars are NOT considered ( due to \K )
(?=(mother|beautiful|car)\h(?:\w+\h){1,6}(?!\1)(mother|beautiful|car))   #   IF [KEY_word_#1 + (any WORD + BLANK char) from 1 to 6 TIMES + KEY_word_#2]
                                                                         #      Start of OVERALL match                     
\1\h                                                                     #      KEY_word_#1 with its BLANK char
((?:(?!(?1)).)+?\h)?                                                     #      The SHORTEST POSSIBLE range of chars DIFFERENT from ALL KEY words, with its BLANK char, till ...
(?!\1|\2)(?1)\h                                                          #      KEY_WORD_#3, with its BLANK char, DIFFERENT from KEY_word_#1 and KEY_word_#2
((?:(?!(?1)).)+?\h)?                                                     #      The SHORTEST POSSIBLE range of chars DIFFERENT from ALL KEY words, with its BLANK char, till ...
\2                                                                       #      Key word #2
</code></pre>
<hr />
<p dir="auto">So :</p>
<ul>
<li>
<p dir="auto">Open the file to test</p>
</li>
<li>
<p dir="auto">Make a <strong>normal</strong> selection of the <strong>all</strong> the text, between the strings <strong><code>(?x)</code></strong> and <strong><code>\2</code></strong>, right above</p>
</li>
<li>
<p dir="auto">Open the <strong>Find</strong> or <strong>Mark</strong> dialog ( with <strong><code>Ctrl + F</code></strong> or <strong><code>Ctrl + M</code></strong> )</p>
</li>
</ul>
<p dir="auto">=&gt; This <strong>selected</strong> text ( the <strong>overall</strong> regex ) should be <strong>inserted</strong> in the <strong><code>Find what:</code></strong> field</p>
<ul>
<li>
<p dir="auto">If the <strong><code>In selection</code></strong> button is ticked, just <strong>untick</strong> that option</p>
</li>
<li>
<p dir="auto">Click on the <strong><code>Fin Next</code></strong> or <strong><code>Mark</code></strong> button</p>
</li>
</ul>
<p dir="auto">Et voilà !</p>
<p dir="auto">BR</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64082</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64082</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 18 Mar 2021 13:24:51 GMT</pubDate></item><item><title><![CDATA[Reply to Regex: Find this 3 words within the range of 8 words on Thu, 18 Mar 2021 05:50:51 GMT]]></title><description><![CDATA[<p dir="auto">hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> and everyone.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> Your regex <code>(?=(mother|beautiful|car)\h(?:\w+\h){1,6}(?!\1)(mother|beautiful|car))</code> only puts the cursor, but is doesn’t make a select from WORD 1 to WORD 2 and WORD 3 <code>(mother ... beautiful ... car)</code></p>
]]></description><link>https://community.notepad-plus-plus.org/post/64070</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64070</guid><dc:creator><![CDATA[Vasile Caraus]]></dc:creator><pubDate>Thu, 18 Mar 2021 05:50:51 GMT</pubDate></item><item><title><![CDATA[Reply to Regex: Find this 3 words within the range of 8 words on Thu, 18 Mar 2021 20:45:21 GMT]]></title><description><![CDATA[<p dir="auto">Hello, vasile, <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">OMG, this problem really gave me a <strong>hard</strong> time !  Indeed, we have <strong>many</strong> conditions to respect :</p>
<p dir="auto"><strong>EDIT</strong> : Indeed, all this post is <strong>obsolete</strong> So refer, instead, to this <strong>other</strong> post, below :    <a href="https://community.notepad-plus-plus.org/post/64093">https://community.notepad-plus-plus.org/post/64093</a></p>
<ul>
<li>
<p dir="auto">Each KEY word ( <strong><code>mother</code></strong> , <strong><code>beautiful</code></strong> and <strong><code>car</code></strong> ) must <strong>all</strong> be present, at least <strong>once</strong>, in <strong>current</strong> line</p>
</li>
<li>
<p dir="auto">The range between the a <strong>first</strong> and a <strong>last</strong> KEY word must <strong>not</strong> contain <strong>more</strong> than <strong><code>8</code></strong> words</p>
</li>
<li>
<p dir="auto">The range to match must contain the <strong>three</strong> KEY words in any <strong>order</strong></p>
</li>
</ul>
<hr />
<ul>
<li>
<p dir="auto">The <strong>first</strong> condition is rather easy with the <strong>three</strong> look-aheads <strong><code>(?=.*mother)(?=.*beautiful)(?=.*car)</code></strong> which are <strong>tested</strong> as soon as the regex engine is at <strong>beginning</strong> of a line</p>
</li>
<li>
<p dir="auto">The <strong>second</strong> condition means that :</p>
<ul>
<li>
<p dir="auto">The <strong>shortest</strong> range is <strong><code>KEY_word_#1 KEY_word_#3 KEY_word_#2</code></strong></p>
</li>
<li>
<p dir="auto">The <strong>greatest</strong> range is <strong><code>KEY_word_#1 word_1 word_2 word_3 wod_4 word_5 KEY_word_#2</code></strong>, with <strong><code>KEY_word_#3</code></strong> being any <strong><code>word_#</code></strong></p>
</li>
</ul>
</li>
</ul>
<p dir="auto">So this <strong>fourth</strong> look-ahead <strong><code>(?=(mother|beautiful|car)\h(?:\w+\h){1,6}(?!\1)(mother|beautiful|car))</code></strong> will be used to be <strong>sure</strong> that the range to match contain <strong>between</strong> <strong><code>3</code></strong> and <strong><code>8</code></strong> words, in totality !</p>
<p dir="auto">Note that the <strong>first</strong> <strong><code>KEY_word_1</code></strong> is the <strong>group <code>1</code></strong> and the <strong>last</strong> <strong><code>KEY_word_#2</code></strong> is the <strong>group <code>2</code></strong>, which must be <strong>different</strong> from <strong><code>KEY_word_1</code></strong>, because of the <strong>negative</strong> look-ahead <strong><code>(?!\1)</code></strong></p>
<ul>
<li>
<p dir="auto">The <strong>third</strong> condition represents the <strong>main</strong> part and searches :</p>
<ul>
<li>
<p dir="auto">The <strong>group <code>1</code></strong>, standing for <strong><code>KEY_word_#1</code></strong>, followed with its <strong>blank</strong> char</p>
</li>
<li>
<p dir="auto">A <strong>possible</strong> range of chars, all different of <strong>all</strong> the KEY words, followed by its <strong>blank</strong> char</p>
</li>
<li>
<p dir="auto">The third KEY word <strong><code>KEY_word_#3</code></strong>, which must be <strong>different</strong> from <strong><code>KEY_word_#1</code></strong> and <strong><code>KEY_word_#2</code></strong>,followed by a <strong>blank</strong> char</p>
</li>
<li>
<p dir="auto">Again, a <strong>possible</strong> range of chars, all different of <strong>all</strong> the KEY words, followed by its <strong>blank</strong> char</p>
</li>
<li>
<p dir="auto">The <strong>group <code>2</code></strong>, standing for <strong><code>KEY_word_#2</code></strong></p>
</li>
</ul>
</li>
</ul>
<hr />
<p dir="auto">Using the <strong>free-spacing</strong> mode, here is this <strong>tricky</strong> search regex :</p>
<pre><code class="language-z">(?x)                                                                     # FREE-SPACING Mode 
(?i-s)                                                                   # Search SENSITIVE to CASE and LIMITED to a SINGLE line, at a time
(?=.*mother)(?=.*beautiful)(?=.*car)                                     # IF EACH KEY word exists, further on, at least ONCE, in CURRENT line
.*?\K                                                                    #   LEADING chars are NOT considered ( due to \K )
(?=(mother|beautiful|car)\h(?:\w+\h){1,6}(?!\1)(mother|beautiful|car))   #   IF [KEY_word_#1 + (any WORD + BLANK char) from 1 to 6 TIMES + KEY_word_#2]
                                                                         #      Start of OVERALL match                     
\1\h                                                                     #      KEY_word_#1 with its BLANK char
((?:(?!(?1)).)+?\h)?                                                     #      The SHORTEST POSSIBLE range of chars DIFFERENT from ALL KEY words, with its BLANK char, till ...
(?!\1|\2)(?1)\h                                                          #      KEY_WORD_#3, with its BLANK char, DIFFERENT from KEY_word_#1 and KEY_word_#2
((?:(?!(?1)).)+?\h)?                                                     #      The SHORTEST POSSIBLE range of chars DIFFERENT from ALL KEY words, with its BLANK char, till ...
\2                                                                       #      Key word #2
</code></pre>
<hr />
<p dir="auto">Remark that the <strong><code>(?1)</code></strong> syntaxes, in some parts of the regex, are <strong>sub-routine calls</strong> to the regex, defined by the <strong>group <code>1</code></strong>, so <strong>strictly identical</strong> to the regex <strong><code>(mother|beautiful|car)</code></strong></p>
<p dir="auto">In order to do some <strong>tests</strong>, use the regex, <strong>below</strong>, and the text that follows !</p>
<pre><code class="language-z">=================================================== Regex in FREE-SPACING mode ========================================
(?x)
(?i-s)
(?=.*aaaa)(?=.*hhhh)(?=.*zzzz)
.*?\K
(?=(aaaa|hhhh|zzzz)\h(?:\w+\h){1,6}(?!\1)(aaaa|hhhh|zzzz))
\1\h
((?:(?!(?1)).)+?\h)?
(?!\1|\2)(?1)\h
((?:(?!(?1)).)+?\h)?
\2
=======================================================================================================================

The KEY words are the THREE strings "aaaa", "hhhh" and "zzzz"

================================================== Cases NOT MATCHED ==================================================

aaaa                                               ONE word ONLY
hhhh                                               ONE word ONLY
zzzz                                               ONE word ONLY

aaaa 111 222 hhhh                                  TWO words ONLY
aaaa 111 222 zzzz                                  TWO words ONLY
hhhh 111 222 zzzz                                  TWO words ONLY


aaaa 111 aaaa 222 aaaa                             SAME word, THREE times
hhhh 111 hhhh 222 hhhh                             SAME word, THREE times
zzzz 111 zzzz 222 zzzz                             SAME word, THREE times


aaaa aaaa 333 hhhh                                 THREE words, but 2 SAME words
aaaa aaaa 333 zzzz                                 THREE words, but 2 SAME words
hhhh hhhh 333 aaaa                                 THREE words, but 2 SAME words
hhhh hhhh 333 zzzz                                 THREE words, but 2 SAME words
zzzz zzzz 333 aaaa                                 THREE words, but 2 SAME words
zzzz zzzz 333 hhhh                                 THREE words, but 2 SAME words

aaaa 111 222 aaaa 333 444 555 hhhh                 THREE words, but 2 SAME words
aaaa 111 222 aaaa 333 444 555 zzzz                 THREE words, but 2 SAME words
hhhh 111 222 hhhh 333 444 555 aaaa                 THREE words, but 2 SAME words
hhhh 111 222 hhhh 333 444 555 zzzz                 THREE words, but 2 SAME words
zzzz 111 222 zzzz 333 444 555 aaaa                 THREE words, but 2 SAME words
zzzz 111 222 zzzz 333 444 555 hhhh                 THREE words, but 2 SAME words


aaaa 111 222 hhhh 333 444 555 666 zzzz             The 3 DIFFERENT words, but in a range of  9 Words  ( so &gt; 8 )
hhhh 111 222 aaaa 333 444 555 666 zzzz             The 3 DIFFERENT words, but in a range of  9 Words  ( so &gt; 8 )
aaaa 111 222 zzzz 333 444 555 666 hhhh             The 3 DIFFERENT words, but in a range of  9 Words  ( so &gt; 8 )
zzzz 111 222 hhhh 333 444 555 666 aaaa             The 3 DIFFERENT words, but in a range of  9 Words  ( so &gt; 8 )
zzzz 111 222 aaaa 333 444 555 666 hhhh             The 3 DIFFERENT words, but in a range of  9 Words  ( so &gt; 8 )
zzzz 111 222 hhhh 333 444 555 666 aaaa             The 3 DIFFERENT words, but in a range of  9 Words  ( so &gt; 8 )

aaaa 111 222 3333 hhhh 444 555 666 777 zzzz        The 3 DIFFERENT words, but in a range of 10 Words  ( so &gt; 8 )
hhhh 111 222 3333 aaaa 444 555 666 777 zzzz        The 3 DIFFERENT words, but in a range of 10 Words  ( so &gt; 8 )
aaaa 111 222 3333 zzzz 444 555 666 777 hhhh        The 3 DIFFERENT words, but in a range of 10 Words  ( so &gt; 8 )
zzzz 111 222 3333 hhhh 444 555 666 777 aaaa        The 3 DIFFERENT words, but in a range of 10 Words  ( so &gt; 8 )
zzzz 111 222 3333 aaaa 444 555 666 777 hhhh        The 3 DIFFERENT words, but in a range of 10 Words  ( so &gt; 8 )
zzzz 111 222 3333 hhhh 444 555 666 777 aaaa        The 3 DIFFERENT words, but in a range of 10 Words  ( so &gt; 8 )

aaaa 111 222 3333 444 hhhh 555 666 777 888 zzzz    The 3 DIFFERENT words, but in a range of 11 Words  ( so &gt; 8 )
hhhh 111 222 3333 444 aaaa 555 666 777 888 zzzz    The 3 DIFFERENT words, but in a range of 11 Words  ( so &gt; 8 )
aaaa 111 222 3333 444 zzzz 555 666 777 888 hhhh    The 3 DIFFERENT words, but in a range of 11 Words  ( so &gt; 8 )
zzzz 111 222 3333 444 hhhh 555 666 777 888 aaaa    The 3 DIFFERENT words, but in a range of 11 Words  ( so &gt; 8 )
zzzz 111 222 3333 444 aaaa 555 666 777 888 hhhh    The 3 DIFFERENT words, but in a range of 11 Words  ( so &gt; 8 )
zzzz 111 222 3333 444 hhhh 555 666 777 888 aaaa    The 3 DIFFERENT words, but in a range of 11 Words  ( so &gt; 8 )

================================================== MATCHED cases ======================================================

aaaa hhhh zzzz                          aaaa hhhh zzzz
aaaa zzzz hhhh                          aaaa zzzz hhhh
hhhh aaaa zzzz                          hhhh aaaa zzzz
hhhh zzzz aaaa                          hhhh zzzz aaaa
zzzz aaaa hhhh                          zzzz aaaa hhhh
zzzz hhhh aaaa                          zzzz hhhh aaaa

Range of 4 WORDS  aaaa 111 hhhh zzzz    aaaa hhhh 111 zzzz
Range of 4 WORDS  aaaa 111 zzzz hhhh    aaaa zzzz 111 hhhh
Range of 4 WORDS  hhhh 111 aaaa zzzz    hhhh aaaa 111 zzzz
Range of 4 WORDS  hhhh 111 zzzz aaaa    hhhh zzzz 111 aaaa
Range of 4 WORDS  zzzz 111 aaaa hhhh    zzzz aaaa 111 hhhh
Range of 4 WORDS  zzzz 111 hhhh aaaa    zzzz hhhh 111 aaaa

aaaa 111 222 hhhh zzzz    aaaa 111 hhhh 222 zzzz    aaaa hhhh 111 222 zzzz
aaaa 111 222 zzzz hhhh    aaaa 111 zzzz 222 hhhh    aaaa zzzz 111 222 hhhh
hhhh 111 222 aaaa zzzz    hhhh 111 aaaa 222 zzzz    hhhh aaaa 111 222 zzzz
hhhh 111 222 zzzz aaaa    hhhh 111 zzzz 222 aaaa    hhhh zzzz 111 222 aaaa
zzzz 111 222 aaaa hhhh    zzzz 111 aaaa 222 hhhh    zzzz aaaa 111 222 hhhh
zzzz 111 222 hhhh aaaa    zzzz 111 hhhh 222 aaaa    zzzz hhhh 111 222 aaaa

Range of 6 WORDS  aaaa 111 222 333 hhhh zzzz    aaaa 111 222 hhhh 333 zzzz    aaaa 111 hhhh 222 333 zzzz    aaaa hhhh 111 222 333 zzzz
Range of 6 WORDS  aaaa 111 222 333 zzzz hhhh    aaaa 111 222 zzzz 333 hhhh    aaaa 111 zzzz 222 333 hhhh    aaaa zzzz 111 222 333 hhhh
Range of 6 WORDS  hhhh 111 222 333 aaaa zzzz    hhhh 111 222 aaaa 333 zzzz    hhhh 111 aaaa 222 333 zzzz    hhhh aaaa 111 222 333 zzzz
Range of 6 WORDS  hhhh 111 222 333 zzzz aaaa    hhhh 111 222 zzzz 333 aaaa    hhhh 111 zzzz 222 333 aaaa    hhhh zzzz 111 222 333 aaaa
Range of 6 WORDS  zzzz 111 222 333 aaaa hhhh    zzzz 111 222 aaaa 333 hhhh    zzzz 111 aaaa 222 333 hhhh    zzzz aaaa 111 222 333 hhhh
Range of 6 WORDS  zzzz 111 222 333 hhhh aaaa    zzzz 111 222 hhhh 333 aaaa    zzzz 111 hhhh 222 333 aaaa    zzzz hhhh 111 222 333 aaaa

aaaa 111 222 333 4444 hhhh zzzz    aaaa 111 222 333 hhhh 4444 zzzz    aaaa 111 222 hhhh 333 4444 zzzz    aaaa 111 hhhh 222 333 4444 zzzz    aaaa hhhh 111 222 333 4444 zzzz
aaaa 111 222 333 4444 zzzz hhhh    aaaa 111 222 333 zzzz 4444 hhhh    aaaa 111 222 zzzz 333 4444 hhhh    aaaa 111 zzzz 222 333 4444 hhhh    aaaa zzzz 111 222 333 4444 hhhh
hhhh 111 222 333 4444 aaaa zzzz    hhhh 111 222 333 aaaa 4444 zzzz    hhhh 111 222 aaaa 333 4444 zzzz    hhhh 111 aaaa 222 333 4444 zzzz    hhhh aaaa 111 222 333 4444 zzzz
hhhh 111 222 333 4444 zzzz aaaa    hhhh 111 222 333 zzzz 4444 aaaa    hhhh 111 222 zzzz 333 4444 aaaa    hhhh 111 zzzz 222 333 4444 aaaa    hhhh zzzz 111 222 333 4444 aaaa
zzzz 111 222 333 4444 aaaa hhhh    zzzz 111 222 333 aaaa 4444 hhhh    zzzz 111 222 aaaa 333 4444 hhhh    zzzz 111 aaaa 222 333 4444 hhhh    zzzz aaaa 111 222 333 4444 hhhh
zzzz 111 222 333 4444 hhhh aaaa    zzzz 111 222 333 hhhh 4444 aaaa    zzzz 111 222 hhhh 333 4444 aaaa    zzzz 111 hhhh 222 333 4444 aaaa    zzzz hhhh 111 222 333 4444 aaaa


Range of 8 WORDS  aaaa 111 222 333 444 555 hhhh zzzz    aaaa 111 222 333 444 hhhh 555 zzzz    aaaa 111 222 333 hhhh 444 555 zzzz    aaaa 111 222 hhhh 333 444 555 zzzz    aaaa 111 hhhh 222 333 444 555 zzzz    aaaa hhhh 111 222 333 444 555 zzzz
Range of 8 WORDS  aaaa 111 222 333 444 555 zzzz hhhh    aaaa 111 222 333 444 zzzz 555 hhhh    aaaa 111 222 333 zzzz 444 555 hhhh    aaaa 111 222 zzzz 333 444 555 hhhh    aaaa 111 zzzz 222 333 444 555 hhhh    aaaa zzzz 111 222 333 444 555 hhhh
Range of 8 WORDS  hhhh 111 222 333 444 555 aaaa zzzz    hhhh 111 222 333 444 aaaa 555 zzzz    hhhh 111 222 333 aaaa 444 555 zzzz    hhhh 111 222 aaaa 333 444 555 zzzz    hhhh 111 aaaa 222 333 444 555 zzzz    hhhh aaaa 111 222 333 444 555 zzzz
Range of 8 WORDS  hhhh 111 222 333 444 555 zzzz aaaa    hhhh 111 222 333 444 zzzz 555 aaaa    hhhh 111 222 333 zzzz 444 555 aaaa    hhhh 111 222 zzzz 333 444 555 aaaa    hhhh 111 zzzz 222 333 444 555 aaaa    hhhh zzzz 111 222 333 444 555 aaaa
Range of 8 WORDS  zzzz 111 222 333 444 555 aaaa hhhh    zzzz 111 222 333 444 aaaa 555 hhhh    zzzz 111 222 333 aaaa 444 555 hhhh    zzzz 111 222 aaaa 333 444 555 hhhh    zzzz 111 aaaa 222 333 444 555 hhhh    zzzz aaaa 111 222 333 444 555 hhhh
Range of 8 WORDS  zzzz 111 222 333 444 555 hhhh aaaa    zzzz 111 222 333 444 hhhh 555 aaaa    zzzz 111 222 333 hhhh 444 555 aaaa    zzzz 111 222 hhhh 333 444 555 aaaa    zzzz 111 hhhh 222 333 444 555 aaaa    zzzz hhhh 111 222 333 444 555 aaaa


111 aaaa 222 333 hhhh 444 555 zzzz
111 aaaa 222 333 zzzz 444 555 hhhh
111 hhhh 222 333 aaaa 444 555 zzzz
111 hhhh 222 333 zzzz 444 555 aaaa
111 zzzz 222 333 aaaa 444 555 hhhh
111 zzzz 222 333 hhhh 444 555 aaaa


       aaaa 111 222 333 hhhh 444 zzzz 555
       aaaa 111 222 333 zzzz 444 hhhh 555
       hhhh 111 222 333 aaaa 444 zzzz 555
       hhhh 111 222 333 zzzz 444 aaaa 555
       zzzz 111 222 333 aaaa 444 hhhh 555
       zzzz 111 222 333 hhhh 444 aaaa 555

111 aaaa 222 333 hhhh 444 zzzz 555
111 aaaa 222 333 zzzz 444 hhhh 555
111 hhhh 222 333 aaaa 444 zzzz 555
111 hhhh 222 333 zzzz 444 aaaa 555
111 zzzz 222 333 aaaa 444 hhhh 555
111 zzzz 222 333 hhhh 444 aaaa 555

=======================================================================================================================
</code></pre>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64068</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64068</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 18 Mar 2021 20:45:21 GMT</pubDate></item><item><title><![CDATA[Reply to Regex: Find this 3 words within the range of 8 words on Wed, 17 Mar 2021 18:20:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vasile-caraus" aria-label="Profile: Vasile-Caraus">@<bdi>Vasile-Caraus</bdi></a> ,</p>
<blockquote>
<p dir="auto">anyone can help me?</p>
</blockquote>
<p dir="auto">Possibly.  But not without assumptions.</p>
<p dir="auto">If you could clarify things like</p>
<ul>
<li>can it be <code>mother one two three four five six seven eight beautiful one two three four five six seven eight car</code>?  or does the distance from mother to car have to be the 8?</li>
<li>do they have to have words in between, or would <code>mother beautiful car</code> match?</li>
<li>does order matter?</li>
<li>what happens when it’s <code>one mother three beautiful five six seven eight car</code> – would it fail because car is the ninth word?  or would it match because from <code>mother</code> to <code>car</code> is only eight words</li>
<li>should it span multiple lines or not?</li>
</ul>
<p dir="auto">Showing us examples of data that should match and data that shouldn’t is always better than making us guess.  no matter how well written, almost no one will come up with a description of their data that is sufficient to get a question like this answered without also providing example data.</p>
<pre><code>mother two three beautiful five six car eight
mother two three ugly five six car eight
mother two three beautify five six vehicle eight
one mother three beautiful five six seven car
mother one two three four five beautiful one two three four five car
</code></pre>
<p dir="auto">Here’s one solution that matches three of the lines with a certain set of assumptions.<br />
<code>(mother)\h+((?:\w+\h+){0,8})(beautiful)\h+((?:\w+\h+){0,8})(car)</code><br />
<img src="/assets/uploads/files/1616005059846-0f19c815-7fb1-4aa1-a200-03baf75502bf-image.png" alt="0f19c815-7fb1-4aa1-a200-03baf75502bf-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">And a slight modification that matches only two, with a more restrictive assumption:<br />
<code>(mother)\h+(?=(?:\w+\h+){0,8}car)((?:\w+\h+){0,8})(beautiful)\h+((?:\w+\h+){0,8})(car)</code><br />
<img src="/assets/uploads/files/1616005115259-d5ec075e-3e0e-47ff-8002-03cad03dcf37-image.png" alt="d5ec075e-3e0e-47ff-8002-03cad03dcf37-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">(The first only requires that there be no more than 8 words between each of the three keywords.  The second uses a lookahead to make sure there are 0-8 words between <code>mother</code> and <code>car</code>, as well as allowing some number of words between each word.)</p>
<p dir="auto">You should know by now that you will get better answers if you make a better problem statement.  Until you provide more, you probably won’t get anything better than that.</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>
]]></description><link>https://community.notepad-plus-plus.org/post/64029</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64029</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 17 Mar 2021 18:20:35 GMT</pubDate></item></channel></rss>