RegExp to split Full Name into First, MI, Last

The question of splitting a full name into first, middle, and last came up today in the forums. This is a pretty common question with many possible solutions. I came up one solution which is a CFMX UDF that utilizes regular expressions to match the different possible combinations of individual names.

The following function, splitFullName, will accept a parameter fullName and return a structure containing keys firstName, mi, and lastName. Even if no matches are found, it will always return a structure with these three keys, but they might be blank.

I’ve tested the function with a few hundred names in the following forms:

  • First Last
  • First MI Last
  • Last, First
  • Last, First MI

The code also includes a function safeMid which is basically a wrapper for mid() but allows passing zero for the position or length without generating an error.

This entry was posted in Uncategorized by Sam. Bookmark the permalink.

5 thoughts on “RegExp to split Full Name into First, MI, Last

  1. Thank you for the coments on your website. Can you recomend a good location for me to find cheap medicines? My mama is not well right now. Can you advice? Thank you.

    Pablo Villarino

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>