Regular Expression for Titles
<p>I'm new to regular expressions and intrigued at their power.  I'd like to come up with a regular expression for generating title case convention.  In general, each word in English titles of books, films, and other works takes an initial capital, except for articles ("a", "an", "the"), the word "to" as part of an infinitive, and prepositions and coordinating conjunctions shorter than five letters ("in", "on", "from", "and", "with"), unless they begin or end a title or subtitle. </p>

<p>Having said that, what I want to do is essentially capitalize the first letter of every word in a string (title) except for the words:</p>

<pre><code>a
an
the
to
in
on
from
and
with
</code></pre>

<p>These words would have the first letter capitalized when it is the first or last word, otherwise they would be all lower case.</p>

<pre><code>Examples:
   A New Kind of Science     (uppercase A - first word)
   Once in a While           (lowercase a - not first/last word)
   The World We Live In      (uppercase The - first word)
   Ghost in the Shell        (lowercase the - not first/last word)
   To Be or Not to Be        (uppercase and lowercase To, to)
</code></pre>

<p>Ideally roman numerals (1-5000) would be all capitalized:</p>

<pre><code>I, II, III, ... (ones)
IV, V, VI, ...  (fives)
IX, X, XI, ...  (tens)
XL, L, LX, ...  (fifties)
XC, C, CX, ...  (hundreds)
XD, D, DX, ...  (five hundreds)
CM, M, MC, ...  (thousands)
</code></pre>

<p>For all permutations see:   <a href="http://romannumerals.babuo.com/roman-numerals-1-5000" rel="nofollow">Roman Numerals</a></p>

<p>Any suggestions on where to start?</p>