<?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[Finding sentences open with quotation marks and  not closed]]></title><description><![CDATA[<p dir="auto">How do I find unclosed quotations? (ie: "Sentence starting with quotation marks and not ending with corresponding quotation marks like this)</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/10686/finding-sentences-open-with-quotation-marks-and-not-closed</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 21:01:33 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/10686.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Oct 2015 16:07:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Finding sentences open with quotation marks and  not closed on Sat, 24 Oct 2015 11:05:20 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <strong>Vittorio</strong>,</p>
<p dir="auto">Thinking again about this topic, I was able to <strong>improve</strong>, a bit, my <strong>previous</strong> search regex.</p>
<p dir="auto">With the regexes below, it’s possible to detect any <strong>ODD</strong> number of <strong>double</strong> quotation characters, <strong><code>"</code></strong>, in a <strong>sentence</strong> or, by default, in a <strong>complete</strong> line of text :-). Naturally, these <strong>new</strong> regexes seem rather tricky, but they do work !!</p>
<p dir="auto">The <strong>first</strong> regex, below, will select the <strong>last</strong> double quotation mark, <strong>NOT</strong> balanced in a <strong>sentence</strong>, or, by default, in a <strong>complete</strong> line :</p>
<p dir="auto">SEARCH <strong><code>(^|\.)(?:([^".\r\n]*)"(?2)")*(?2)\K"(?=(?2)(\.|$))</code></strong></p>
<p dir="auto"><strong>NOTES</strong> :</p>
<ul>
<li>
<p dir="auto">The <strong>first</strong> group <strong>1</strong>, <strong><code>(^|\.)</code></strong>, represents a <strong>beginning</strong> of line or the possible <strong>dot</strong> of the previous <strong>sentence</strong>.</p>
</li>
<li>
<p dir="auto">The group <strong><code>(?:([^".\r\n]*)"(?2)")</code></strong> represents any range, even <strong>null</strong> of <strong>well-balanced</strong> suites, of the form <strong><code>....."..."..."......"</code></strong>. Note that it’s a <strong>non-capturing</strong> group, due to the syntax <strong><code>?:</code></strong>, at beginning of that group.</p>
</li>
<li>
<p dir="auto">Therefore, the <strong>second</strong> group <strong>2</strong> is <strong><code>([^".\r\n]*)</code></strong>, <strong>inside</strong> the <strong>non-capturing</strong> group, which represents any range, even <strong>null</strong>, of characters, different from a <strong>double</strong> quotation character, a <strong>dot</strong> character and an <strong>EOL</strong> character.</p>
</li>
<li>
<p dir="auto">The regex of this <strong>second</strong> group, is re-used, <strong>further</strong>, in the regex, as a <strong>called subroutine</strong> <strong><code>(?2)</code></strong> to that <strong>group 2</strong>. <em>So, writing the syntax <strong><code>(?2)</code></strong> is <strong>exactly</strong> like writing the regex <strong><code>[^".\r\n]*</code></strong> !</em></p>
</li>
<li>
<p dir="auto">And, like in my <strong>previous</strong> post, the <strong>final</strong> regex, searched, is the <strong>double</strong> quotation, only, after the <strong><code>\K</code></strong> syntax and before the look-ahead <strong><code>(?=(?2)(\.|$))</code></strong>, which looks a range of characters, not <strong><code>"</code></strong>, nor <strong><code>.</code></strong>, till the end of the <strong>sentence</strong> or the <strong>line</strong>.</p>
</li>
</ul>
<hr />
<p dir="auto">The <strong>second</strong> regex will <strong>stop</strong> at the <strong>beginning</strong> of any <strong>line</strong> or <strong>sentence</strong>, which contains an <strong>ODD</strong> number of <strong>double</strong> quotation characters :</p>
<p dir="auto">SEARCH <strong><code>(^|\.)\K(?=(?:([^".\r\n]*)"(?2)")*(?2)"(?2)(\.|$))</code></strong></p>
<p dir="auto"><strong>NOTES</strong> :</p>
<ul>
<li>
<p dir="auto">This time, that <strong>second</strong> regex matches the <strong>empty</strong> string, located, between the a <strong>beginning</strong> of line ( or a <strong>dot</strong> of a previous sentence ) and a <strong>look-ahead</strong>, that tries to detect , FROM this <strong>current</strong> position,  if there an <strong>odd</strong> number of <strong>double</strong> quotation marks, till the end of a <strong>sentence</strong> or a <strong>line</strong> !</p>
</li>
<li>
<p dir="auto">So you’re immediately <strong>aware</strong> that there’s an <strong>unbalanced double</strong> quotation character, <strong>further</strong> on the <strong>current</strong> line :-)</p>
</li>
</ul>
<hr />
<p dir="auto">To see the behaviour of these <strong>two</strong> regexes, just do a <strong>test</strong>, on the simple subject text below :</p>
<pre><code>Line 1 "
Line 2 ""
Line 3 """
Line 4 """"
Line 5 """""
Line 6 """""". "Second" "sentence
</code></pre>
<ul>
<li>
<p dir="auto">With the <strong>first</strong> regex, it should select the <strong>last</strong> <strong><code>"</code></strong> character of the lines <strong>1</strong>, <strong>3</strong> and <strong>5</strong>, only, and the <strong><code>"</code></strong>, just <strong>before</strong> the word <strong>sentence</strong>.</p>
</li>
<li>
<p dir="auto">With the <strong>second</strong> regex, the <strong>cursor</strong> should be located, at <strong>beginning</strong> of the lines <strong>1</strong>, <strong>3</strong> and <strong>5</strong>, only, and just after the <strong>dot</strong> , on line <strong>6</strong>.</p>
</li>
</ul>
<hr />
<p dir="auto">To end with :</p>
<ul>
<li>
<p dir="auto">You may, of course, change, in the regex, the <strong>double</strong> quotation mark by a <strong>single</strong> quotation mark, for instance. However, note that these regexes above, are <strong>NOT</strong> suitable, when the <strong>start</strong> and <strong>stop</strong> character are <strong>different</strong>, as for the couple <strong><code>(</code></strong> and <strong><code>)</code></strong> or even the <strong>French</strong> quotation marks <strong><code>“</code></strong> and <strong><code>”</code></strong> ! It’s an other story… )</p>
</li>
<li>
<p dir="auto">If you don’t care about the notion of <strong>sentences</strong>, you can simplify these regexes, changing the <strong>anchor</strong> <strong><code>(^|\.)</code></strong> into <strong><code>^</code></strong> and the <strong>anchor</strong> <strong><code>(\.|$)</code></strong> into <strong><code>$</code></strong></p>
</li>
</ul>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/11814</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/11814</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sat, 24 Oct 2015 11:05:20 GMT</pubDate></item><item><title><![CDATA[Reply to Finding sentences open with quotation marks and  not closed on Wed, 21 Oct 2015 18:17:53 GMT]]></title><description><![CDATA[<p dir="auto">Hello <strong>Vittorio</strong>,</p>
<p dir="auto">Let’s imagine the simple <strong>English</strong> text, below :</p>
<pre><code>He said "I'm glad to see you". Then, he invited me to come in, saying "Let's have a drink" and, also, "Make yourself at home" !
</code></pre>
<ul>
<li>
<p dir="auto">If you forget the <strong>end</strong> quotation after the word <strong>you</strong> you, still, can detect an <strong>unbalanced</strong> quotation mark, considering the <strong>first</strong> sentence, ending on the <strong>dot</strong> symbol.</p>
</li>
<li>
<p dir="auto">But, if you forget, in the <strong>second</strong> sentence, both, the <strong>end</strong> quotation after the word <strong>drink</strong> and the <strong>start</strong> quotation, before the word <strong>Make</strong>, you, still, have a <strong>balanced</strong> quotation marks, which <strong>WON’T</strong> be detected !</p>
</li>
</ul>
<p dir="auto">On the other hand, detecting <strong>unbalanced SINGLE</strong> quotation mark is <strong>very</strong> difficult, in English, because of the <strong>abbreviated</strong> forms ( as <strong>I’m</strong>, <strong>we’re</strong>…), <strong>possessive</strong> forms ( as <strong>Mary’s hat</strong> ), and so on… !</p>
<hr />
<p dir="auto">But, given the <strong>hypothesis</strong> that <em>there should be <strong>ONLY ONE balanced DOUBLE</strong> quotation marks, per <strong>sentence</strong> or per <strong>line</strong></em>, a regex, searching for an <strong>UNIQUE DOUBLE</strong> quotation symbol, can be built and could solve your problem !</p>
<p dir="auto">So, follow the fews steps below :</p>
<ul>
<li>
<p dir="auto">Open the <strong>Find</strong> dialog  ( <strong>CTRL + F</strong> )</p>
</li>
<li>
<p dir="auto">Set the <strong>Regular expression</strong> mode</p>
</li>
<li>
<p dir="auto">In the <strong>Find what</strong> zone, type the regex <strong><code>(^|\.)[^"]*\K"(?=[^"]*(\.|$))</code></strong></p>
</li>
<li>
<p dir="auto">If necessary, check the <strong>Wrap around</strong> option</p>
</li>
<li>
<p dir="auto">Click, once, on the <strong>Find Next</strong> button</p>
</li>
<li>
<p dir="auto">Hit the <strong>ESC</strong> key to close the <strong>Find</strong> dialog</p>
</li>
<li>
<p dir="auto">Go on, searching, in the <strong>downward</strong> direction, hitting the <strong>F3</strong> key or in the <strong>upward</strong> direction , with the <strong>SHIFT + F3</strong> shortcut</p>
</li>
</ul>
<p dir="auto">This regex will select any <strong>UNIQUE DOUBLE</strong> quotation mark, found in each <strong>sentence</strong>, of a text.</p>
<hr />
<p dir="auto"><strong>NOTES</strong> :</p>
<ul>
<li>
<p dir="auto">A sentence is supposed to <strong>begin</strong> at the beginning of a line ( <strong><code>^</code></strong> ) OR after a <strong>DOT</strong> symbol ( <strong><code>\.</code></strong> )</p>
</li>
<li>
<p dir="auto">A sentence is supposed to <strong>end</strong>, at a <strong>DOT</strong> symbol ( <strong><code>\.</code></strong> ) OR at the end of a line ( <strong><code>$</code></strong> )</p>
</li>
<li>
<p dir="auto">The syntax <strong><code>[^"]*</code></strong> means <strong>any</strong> range of characters, even <strong>null</strong>, <strong>different</strong> from a <strong>double</strong> quotation mark.</p>
</li>
<li>
<p dir="auto">The syntax <strong><code>(?=[^"]*(\.|$))</code></strong> is a positive <strong>look-ahead</strong>, which <strong>MUST</strong> be verified, but that is <strong>NOT</strong> part of the regex. It means that, after finding the first <strong>"</strong> symbol, <strong>no other double</strong> quotation mark occur, till the <strong>end</strong> of the current sentence OR till the end of a the current line, if NO dot is found.</p>
</li>
<li>
<p dir="auto">The <strong><code>\K</code></strong> syntax, before the <strong>double</strong> quotation mark, means that all which have been found, <strong>previous</strong> to the <strong>\K</strong> symbol, is <strong>forgotten</strong> and that the current regex to search is ONLY the <strong>double</strong> quotation mark, located <strong>between</strong> the <strong><code>\K</code></strong> form and the look-ahead <strong><code>(?=[^"]*(\.|$))</code></strong>.</p>
</li>
</ul>
<hr />
<p dir="auto">Of course, it will match, indifferently, the <strong>UNIQUE start</strong> OR the <strong>UNIQUE end</strong> double quotation mark, of a sentence. Afterwards, it’s up to you to appreciate at which location the <strong>missing double</strong> quotation should occur !</p>
<p dir="auto">For instance, do the search, on these <strong>two</strong> sentences, with <strong>unbalanced</strong> quotation marks, below :</p>
<pre><code>He said "I'm glad to see you.

He said I'm glad to see you".
</code></pre>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/11781</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/11781</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Wed, 21 Oct 2015 18:17:53 GMT</pubDate></item></channel></rss>