title: Ruby regex: split string with match beginning with either a newline or the start of the string?
body: <p>Here's my regular expression that I have for this. I'm in Ruby, which — if I'm not mistaken — uses POSIX regular expressions.</p>
  
  <pre><code>regex = /(?:\n^)(\*[\w+ ?]+\*)\n/
  </code></pre>
  
  <p>Here's my goal: I want to split a string with a regex that is <code>*delimited by asterisks*</code>, including those asterisks. <em>However</em>: I only want to split by the match if it is prefaced with a newline character (<code>\n</code>), or it's the start of the whole string. This is the string I'm working with.</p>
  
  <pre><code>"*Friday*\nDo not *break here*\n*But break here*\nBut again, not this"
  </code></pre>
  
  <p>My regular expression is not splitting properly at the <code>*Friday*</code> match, but it <em>is</em> splitting at the <code>*But break here*</code> match (it's also throwing in a <code>here</code> split). My issue is somewhere in the first group, I think: <code>(?:\n^)</code> — I know it's wrong, and I'm not entirely sure of the correct way to write it. Can someone shed some light? Here's my complete code.</p>
  
  <pre><code>regex = /(?:\n^)(\*[\w+ ?]+\*)\n/
  str = "*Friday*\nDo not *break here*\n*But break here*\nBut again, not this"
  str.split(regex)
  </code></pre>
  
  <p>Which results in this:</p>
  
  <pre><code>&gt;&gt;&gt; ["*Friday*\nDo not *break here*", "*But break here*", "But again, not this"]
  </code></pre>
  
  <p>I want it to be this:</p>
  
  <pre><code>&gt;&gt;&gt; ["*Friday*", "Do not *break here*", "*But break here*", "But again, not this"]
  </code></pre>
  
  <p><strong>Edit #1</strong>: I've updated my regex and result. (2011/10/18 16:26 CST)<br>
  <strong>Edit #2</strong>: I've updated both again. (16:32 CST)</p>