Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8337517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:19:37+00:00 2026-06-09T04:19:37+00:00

How can I split a fullname into single, medium and last name? Obviously, it

  • 0

How can I split a fullname into single, medium and last name?

Obviously, it is impossible to cover all posibilities. I only want one rule: If after the word there is other word from 3 letter or less, it must join it with the next word.

Also, I am supposing that the fullname has 3 words or more.

I really have no idea even how to start.

For example:

John Martin Jackson:

  • name1: John
  • name2: Martin
  • name3: Jackson

Steven Ponce de Leon Presley

  • name1: Steven
  • name2: Ponce de Leon
  • name3: Presley

Michael de la Rosa Martin Jackson:

  • name1: Michael de la Rosa
  • name2: Martin
  • name3: Jackson

:S

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:19:39+00:00Added an answer on June 9, 2026 at 4:19 am

    A really fancy regex could do that. To match one name, use

    /\S+((\s+\S{1,3})+\s+\S+)*/
    

    Then, combine three of them with non-matching groups, but each wrapped in one, joined by whitespaces:

    /^(\S+(?:(?:\s+\S{1,3})+\s+\S+)*)\s+(\S+(?:(?:\s+\S{1,3})+\s+\S+)*)\s+(\S+(?:(?:\s+\S{1,3})+\s+\S+)*)$/
    

    To make it match people without a middle name, make that optional:

    /^(\S+(?:(?:\s+\S{1,3})+\s+\S+)*)(?:\s+(\S+(?:(?:\s+\S{1,3})+\s+\S+)*))?\s+(\S+(?:(?:\s+\S{1,3})+\s+\S+)*)$/
    

    Update: Don’t try to match whole names in one regex. Just use the first (simple) regex with a global flag:

    > "Steven Ponce de Leon Presley".match(/\S+((\s+\S{1,3})+\s+\S+)*/g)
    ["Steven", "Ponce de Leon", "Presley"]
    

    Explanation:

    /
     \S+      match a word
     (         followed by any number of
      (         at least one
       \s+       whitespace-separated
       \S{1,3}   up-to-three-letters word
      )+
      \s+       and a whitespace-separated
      \S+       word
     )*
    /g
    

    However, I think an algorithm with some string and array functions would make it clearer what happens, and allows more customisation of the matching process:

    var names = input.split(/s+/);
    if (names.length < 2)
        return; // special case handling for only one word
    var short = 0;
    for (var i=names.length-2; i>=0; i--) {
        // starting at the second-to-last, I expect names not to end with a short one
        if (names[i].length < 4) {
            short++;
        } else if (short) {
            names[i] += " "+names.splice(i+1, short+1).join(" ");
            short = 0;
        }
    }
    return names; // an Array with at least one name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I split a string such as Mar10 into Mar and 10 in
If I want a part of an array I can use [] or split
Trying to write a regex that can parse a full name and split it
How I can split a string into 2D array. String is like 1c2c3r4c5c6r6c8c9 array
I want to know how i can split a string in php based on
Can split(string, array, separator) in awk use sequence of whitespaces as the separator (or
Do MySQL have any function by which I can split data of a column
When I write: MyClass *obj = [[MyClass alloc]init]; I can split in 2 parts:
How can I split a String by Unicode range in Ruby. I wanted to
how can I split this barcode by group separator with Progress? I've tried chr(29)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.