There's no rule you can write which will cover every possible case like
this.  Such is the folly in relying on computerized algorithms for
spelling and grammar issues which do not always follow a set of logical
rules, especially for things such as proper names.  There are a lot of
assumptions that we Westerners tend to make about proper names that
others may not like.

Some names, or parts of names, are not meant to be capitalized at all,
such as Mies van der Rohe, and there are almost a limitless number of
other exceptions to first-letter capitalization, such as Sam O'Neil,
Jenny McCarthy, Beverly d'Angelo, Leonardo di Caprio, Don Alejandro de
la Vega, and Werner von Braun, to name a few.  Other names may have
capitalization that's seemingly random, like "JosePhine" or "JimBob",
which may not make sense to you or me, but the only person who can truly
dictate the proper spelling and capitalization of a name is the owner.
Capitalization becomes even more arbitrary with names of things that are
not people, like for instance, the names JavaScript and FusionPro.

The only thing you can really do is to follow the mantra, Know Thy Data.
My best advice is to rework your job to not change the capitalizations
of proper nouns at all.

Keeping that huge caveat in mind, if you really must capitalize
everything, you can *try* a couple of algorithms which will reduce the
number of egregious problems.

I posted a similar solution for exceptions to the ToTitleCase algorithm
a couple of weeks ago:

    var text = "hi there CEO of the big corp.";
    var result = ToTitleCase(text);

    var Exceptions = [ "CEO", "CFO", "VP", "and", "the", "of", "to" ];
    for (var i in Exceptions)
      var re = RegExp("\\b" + Exceptions[i] + "\\b", "gi");
      result = result.replace(re, Exceptions[i]);

    return result;

But that deals with entire words.  This would replace prefixes like the
type you describe:

    var text = "joe mcdonald macmillan laplace landry";
    var result = ToTitleCase(text);

    var Prefixes = [ "Mc", "Mac", "De", "La" ];
    for (var i in Prefixes)
        var re = RegExp("\\b" + Prefixes[i] + "\\w", "g");
        result = result.replace(re,
             function(w){return w.substring(0, w.length-1) +

    return result;

But that's still for "title case," and you're looking for exceptions to
"all caps."  So something like this would work:
    var text = "joe mcdonald macmillan laplace landry";
    var result = ToUpper(text);

    var Prefixes = [ "Mc", "Mac", "De", "La" ];
    for (var i in Prefixes)
        var re = RegExp("\\b" + Prefixes[i] + "\\w", "gi");
        result = result.replace(re, function(w){return Prefixes[i] +

    return result;

But, note that those last two algorithms will catch all names starting
with one of the prefixes, and will erroneously uncapitalize letters in a
name like "Landry" or "Macintosh."  I think the best logic for what
you're describing is to look for words which already have a capital
letter that's not at the first position in the original string, like so:

    var text = "Joe McDonald MacMillan LaPlace Landry";
    var result = ToUpper(text);

    var Prefixes = [ "Mc", "Mac", "De", "La" ];
    for (var i in Prefixes)
        var re = RegExp("\\b" + Prefixes[i] + "[A-Z]", "g");
        var pos = -1;
        var matches;
        while (matches = re.exec(text))
          result = result.substring(0, matches.index) +
                matches[0] + result.substring(re.lastIndex);

    return result;

This, of course, assumes that the capitalization is correct in the
original name.  And it's hardly a universal solution, since it's limited
to the number of prefixes you give it.  And it still will not properly
handle stand-alone uncapitalized words in names such as "van" or "de",
but those could be handled with an exception list as in the first
example above.  You still won't ever get every possible case right,
however.  Again, my best advice is to leave proper nouns and names in
their original format.  Otherwise, no matter how many exceptions you
add, you'll forever be getting complaints from a client that a name is
not right.

Here is an online article which attempts to solve this kind of problem:

Note that it's in Java, which is a different language than JavaScript,
but the general ideas are the same.


Calling all FP Web Users!

Do you have a question or lots of knowledge to share about FusionPro Web?

If so, join our Printable Web to Print Users' Forum today!

Send email to [EMAIL PROTECTED] to find out how!

Users of FusionPro Desktop have unlimited free email support. Contact Printable 
View FusionPro Knowledge Base, FusionPro Samples at

You are currently subscribed to fusionpro as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

Note:  All e-mail sent to or from this address will be received or otherwise 
recorded by the e-mail recipients of this forum. It is subject to archival, 
monitoring or review by, and/or disclosure to someone other than the recipient. 
Our privacy policy is posted on

Reply via email to