Forum Academy Marketplace Showcase Pricing Features

Simples way to extract NAME and LAST NAME

After trying (without success) to use regex to extract the NAME and LAST NAME of an user, I decided to do it thru javascript. It is a very very simple solution, so I decided to share it here so it may help others with this kind of need.

var name_array = name.split(" ");
console.log (name_array[0] + " " + name_array[name_array.length-1] )

What the code above do is to pick a full name and transform it in a Array, using the blank spaces between the words as separators. In the end, the code dysplays the FIRST and LAST element of the Array.

So a name as “Barack Hussein Obama” will create the Array:

var name_array = ["Barack", "Hussein", "Obama"]

First element: name_array[0] is Barack
Last element: name_array[name_array.length-1] is Obama

So, using Toolbox plugin, you can extract the result and post it back into Bubble. Very simple.

Hope it helps someone!

1 Like

Neat method, thanks for sharing! Maybe irrelevant at this point, but if it’s helpful, the following regex would also do it.

^([\S]+) gives you everything before the first space (first name)

\ (.*) gives you everything after the first space (last names)


Similarly to andrew’s first solution, this extracts a list of the words in a string, you can then simply pull the first item to get the first name, and then “items from 2” to get the rest. It leaves the spaces behind and only extracts actual words.


1 Like

Any ideas on how to extract the text after the “@” in an email input?

Thanks @andrew.illingworth91 and @aj11

But if I just wanted the first and the LAST name? And not all the names after the first?

Imagine a full name with “4 names”…

Bubble have a native function for this :+1:



In some Latin American countries it’s not unheard of to carry your mother and fathers last names. So maybe? But probably not in most cases
Or what if the first name was

Jared Jr.

You may miss this as well. Hmm. Idk. Just thinking of different scenarios.

That is my case.

  • Name
  • Midle name (mother’s last name)
  • Last name (father’s last name)

So here in Brazil, we use the name and the last name for almost everything…

1 Like

Use my regex solution and then just use the last item in the extracted list. The last item is the last name. The first item is the first name. Item# 2 would be the middle name.


Super helpful, thank you!