Regex to split a string on number of characters but to get whole words
<p>I'm currently using a regular expression to split a string into substrings of 15 characters:</p>

<pre><code>(?&lt;=\G.{15})
</code></pre>

<p>Example text:
First second third fourth fifth sixthsixthsixthsixthsixthsixth seventh</p>

<p>splits into:</p>

<pre><code>[0] =&gt; First second th
[1] =&gt; ird fourth fifth
[2] =&gt;  sixthsixthsixth
[3] =&gt; sixthsixthsixths
[4] =&gt; ixth seventh
</code></pre>

<p>I would like to modify this a bit to:
Split into 15 characters or less, but only split on whitespace in order to get whole words.
If there is a word from the split in #1 that is longer than 15 characters then split that.</p>

<p>This could get messy though. If I have a word that is longer than 15 characters I want that word to be split, and then the following substring should 15 characters also, not just the second half of the word. </p>

<p>For the above example, I would like:</p>

<pre><code>[0] =&gt; First second 
[1] =&gt; third fourth 
[2] =&gt; fifth
[3] =&gt; sixthsixthsixth
[4] =&gt; sixthsixthsixth 
[5] =&gt; sixth seventh
</code></pre>

<p>I would also be happy with:</p>

<pre><code>[0] =&gt; First second 
[1] =&gt; third fourth 
[2] =&gt; fifth sixthsixt
[3] =&gt; hsixthsixthsixt
[4] =&gt; hsixthsixth 
[5] =&gt; seventh
</code></pre>

<p>If the first two cannot be done in a single regex then I might be happy with:</p>

<pre><code>[0] =&gt; First second 
[1] =&gt; third fourth 
[2] =&gt; fifth
[3] =&gt; sixthsixthsixth
[4] =&gt; sixthsixthsixth 
[5] =&gt; sixth 
[6] =&gt; seventh
</code></pre>

<p>the difference between the two is that I split the long string in a different spot.</p>

<p>Is it possible to do this with a single regex?</p>