title: Regex that gets a sentence containing a name
body: <p>I am creating regexes that get the whole sentence if a piece of specific information exists. Right now I am working on my name regex, so if there is any composed name (example: &quot;Jorge Martel&quot;, &quot;Jorge Martel del Arnold Albuquerque&quot;) the regex should get the whole sentence that has the name.</p>
  <p><strong>If I have these two sentences:</strong></p>
  <p>(1) - &quot;A hardworking guy is working at the supermarket. They call him Jorge Horizon, but that's not his real name.&quot;</p>
  <p>(2) - &quot;He has an identity document that contains the name, Jorge Martel Arnold.&quot;</p>
  <p><strong>The regex should return these two results from the sentences above:</strong></p>
  <p>(1) - &quot;They call him Jorge Horizon, but that's not his real name.&quot;</p>
  <p>(2) - &quot;He has an identity document that contains the name, Jorge Martel Arnold.&quot;</p>
  <p>This is my regex:</p>
  <pre><code>(?:(?(?&lt;=[\.!?]\s([A-Z]))(.+?[^.])|))?((?:(?:[A-Z][A-zÀ-ÿ']+\s(?:(?:(?:[A-zÀ-ÿ']{1,3}\s)?(?:[A-ZÀ-Ÿ][A-zÀ-ÿ']*\s?))+))\b)(.+?[\.!?](?:\s|\n|\Z)))
  </code></pre>
  <p>Basically, it verifies if there is a dot, exclamation, or interrogation symbol with a blank space and an upper case character and tells the regex that everything must be select, else it should get all the sentence.</p>
  <p>My else case (|) right now is empty, because using (.+?) avoids my first condition...</p>
  <p><strong>Regex without the else case:</strong></p>
  <p><a href="https://i.stack.imgur.com/5aMll.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5aMll.png" alt="Validates until the dot, but doesn't get the second sentence" /></a></p>
  <p>Validates until the dot, but doesn't get the second sentence.</p>
  <p><strong>Regex with the else case:</strong></p>
  <p><a href="https://i.stack.imgur.com/gsN5k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gsN5k.png" alt="Validates the whole sentence, but doesn't get the first sentence" /></a></p>
  <p>Validates the second sentence, but overrides the first condition that appears in the first sentence.</p>
  <p>I expect my regex to return correctly the sentences:</p>
  <ul>
  <li>&quot;They call him Jorge Horizon, but that's not his real name.&quot;</li>
  <li>&quot;He has an identity document that contains the name, Jorge Martel Arnold.&quot;</li>
  </ul>
  <p>I have also created a text to validate the regex operations as I will be using it a lot in texts. I added a lot of conditions in this text, which will probably appear in my daily work.</p>
  <p>Check my regex, sentence, and text <a href="https://regex101.com/r/jEc8h9/5" rel="nofollow noreferrer">here</a>:</p>
  <p>Does anyone know what should I change in my regex? I have tried many variations and still cannot find the solution.</p>
  <p>P.S.: I intend to use it in my python code, but I need to fix it with the regex and not with the python code.</p>