title: How do I select the 1st n characters or through the fist "<"?
body: <p>I am auto-generating an incipit (first bit of a string as an intro) using regex. The incipit is used in a Twig template. The original string can include html. If my incipit ends within html tags, it breaks the Twig template. I want to get the first 260 characters <strong>OR</strong> all characters from the beginning of the string to the first <code>&lt;</code>, whichever is <strong>fewer characters</strong>.</p>
  
  <p>This works for first 260 characters:</p>
  
  <pre><code>if (preg_match('/^.{1,260}\b/s', $body, $match)) {
      $incipit=$match[0]; 
      if (strlen($body &gt;= 260)) {
          $incipit .= "&amp;hellip;"; //adding ellipsis only if body is truncated 
      } 
  }
  </code></pre>
  
  <p>I tried adding an or within my regex. </p>
  
  <pre><code>preg_match('/^.{1,260}\b|[^&gt;]/s', $body, $match))
  </code></pre>
  
  <p>But, that does not work the <code>|</code> seems to be ignored.</p>