title: PHP Regex match first newline after x characters for a trimming function
body: <p>I'm writing a trimming function that takes a string and finds the first newline <code>\n</code> character after the 500th character and returns a string up to the newline. Basically, if there are <code>\n</code> at indices of 200, 400, and 600, I want the function to return the first 600 characters of the string (not including the <code>\n</code>).</p>
  
  <p>I tried:</p>
  
  <pre><code>$output = preg_replace('/([^%]{500}[^\n]+?)[^%]*/','$1',$output);
  </code></pre>
  
  <p>I used the percent sign because I couldn't find a character class that just encompassed "everthing". Dot didn't do it because it excluded newlines. Unfortunately, my function fails miserably. Any help or guidance would be appreciated.</p>