Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This ought to do it.</p> <pre><code>/* Assumptions: - Sentence separators are a combination of terminators (.!?) + doublequote (optional) + spaces + capital letter. - I haven't preserved tags if it gets down to removing the last sentence. */ function removeLastSentence(text) { lastSeparator = Math.max( text.lastIndexOf("."), text.lastIndexOf("!"), text.lastIndexOf("?") ); revtext = text.split('').reverse().join(''); sep = revtext.search(/[A-Z]\s+(\")?[\.\!\?]/); lastTag = text.length-revtext.search(/\/\&lt;/) - 2; lastPtr = (lastTag &gt; lastSeparator) ? lastTag : text.length; if (sep &gt; -1) { text1 = revtext.substring(sep+1, revtext.length).trim().split('').reverse().join(''); text2 = text.substring(lastPtr, text.length).replace(/['"]/g,'').trim(); sWithoutLastSentence = text1 + text2; } else { sWithoutLastSentence = ''; } return sWithoutLastSentence; } /* TESTS: var text = '&lt;p&gt;Blabla, some more text here. Sometimes &lt;span&gt;basic&lt;/span&gt; html code is used but that should not make the "selection" of the text any harder! I looked up the window and I saw a plane flying over. I asked the first thing that came to mind: "What is it doing up there?" She did not know, "I think we should move past the fence!", she quickly said. He later described it as: "Something insane. "&lt;/p&gt;'; alert(text + '\n\n' + removeLastSentence(text)); alert(text + '\n\n' + removeLastSentence(removeLastSentence(text))); alert(text + '\n\n' + removeLastSentence(removeLastSentence(removeLastSentence(text)))); alert(text + '\n\n' + removeLastSentence(removeLastSentence(removeLastSentence(removeLastSentence(text))))); alert(text + '\n\n' + removeLastSentence(removeLastSentence(removeLastSentence(removeLastSentence(removeLastSentence(text)))))); alert(text + '\n\n' + removeLastSentence(removeLastSentence(removeLastSentence(removeLastSentence(removeLastSentence(removeLastSentence(text))))))); alert(text + '\n\n' + removeLastSentence('&lt;p&gt;Blabla, some more text here. Sometimes &lt;span&gt;basic&lt;/span&gt; html code is used but that should not make the "selection" of the text any harder! I looked up the ')); */ </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload