title: Regex - remove sentences starting with certain words only if it is the last sentence
body: <p>As per the title, I am trying to clean a large compilation of short texts, to remove sentences that start with certain words -- but only if it is the <strong>last</strong> of <strong>&gt;1</strong> sentences that text.</p>
  <p>Suppose I want to cut out the last sentence if it begins with 'Jack is ...'<br />
  Here is an example with varied cases:</p>
  <pre><code>test_strings &lt;- c(&quot;Jack is the tallest person.&quot;, 
                    &quot;and Jack is the one who said, let there be fries.&quot;, 
                    &quot;There are mirrors. And Jack is there to be suave.&quot;, 
                    &quot;There are dogs. And jack is there to pat them. Very cool.&quot;, 
                    &quot;Jack is your lumberjack. Jack, is super awesome.&quot;,
                    &quot;Whereas Jack is, for the whole summer, sound asleep. Zzzz&quot;, 
                    &quot;'Jack is so cool!' Jack is cool. Jack is also cold.&quot;
                    )
  </code></pre>
  <p>And here is the regex I currently have: <code>&quot;(?![A-Z'].+[\\.|'] )[Jj]ack,? is.+\\.$&quot;</code></p>
  <pre><code>map_chr(test_strings, ~str_replace(.x, &quot;(?![A-Z'].+[\\.|'] )[Jj]ack,? is.+\\.$&quot;, &quot;[TRIM]&quot;))
  </code></pre>
  <p>Producing these results:</p>
  <pre><code>[1] &quot;[TRIM]&quot;                                                   
  [2] &quot;and [TRIM]&quot;                                               
  [3] &quot;There are mirrors. And [TRIM]&quot;                            
  [4] &quot;There are dogs. And [TRIM]&quot;                               
  [5] &quot;Jack is your lumberjack. [TRIM]&quot;                          
  [6] &quot;Whereas Jack is, for the whole summer, sound asleep. Zzzz&quot;
  [7] &quot;'Jack is so cool!' Jack is cool. [TRIM]&quot;  
  
  
  ## Basically my current regex is still too greedy. 
  ## No trimming should happen for the first 4 examples. 
  ## 5 - 7th examples are correct. 
  
  ## Explanations:
  # (1) Wrong. Only one sentence; do not trim, but current regex trims it. 
  # (2) Wrong. It is a sentence but does not start with 'Jack is'.
  # (3) Wrong. Same situation as (2) -- the sentence starts with 'And' instead of 'Jack is'
  # (4) Wrong. Same as (2) (3), but this time test with lowercase `jack`
  # (5) Correct. Trim the second sentence as it is the last. Optional ',' removal is tested here.
  # (6) Correct.
  # (7) Correct. Sometimes texts do not begin with alphabets. 
  </code></pre>
  <p>Thanks for any help!</p>