I tried my best to find another thread on this topic but I just couldn’t find any. I’m wondering if there is a way to use :truncate on a text field to extract the first part of a name up to the first space. The assumption I’m making is that my users are writing their full name in the form of “first name last name” of course.
I’ve been trying to use the :truncate function and also the extract and replace. But I can’t quite do it. I’m guessing it’s not possible.
But if anyone has succeeded on this, could you please share how you did it exactly so I could try.
Is there a reason they need to enter it in a single field or can you have them do first name field and last name field? Then you could have a full name field that equals those two values. That might be easier!
This is great; thanks for step-by-step. I just have a quick question. If I were to use ‘find and replace’ to extract the “last name” as well, from a “full name” field, is this the way to do it?
Within a Text Element:
“Current User’sFullName:find and replace”
Leave regex pattern unchecked
In “Text to find” enter:
“Current User’sFullName:find and replace”
Check regex pattern
Insert " .*(?:\n|$)"
Leave the replace empty
-Go back to the original find and replace window
-Leave the replace empty
I did this and it does end up displaying the “last name”, but I wasn’t sure if there was a better way, or a “regex” pattern which would extract the “last name” instead?
I actually just found a simpler method. If anyone here is more knowledgable with Regular Expression, please inform me if I’m using them wrong as I’m a real newbie with RegEx.
The gist is that each bracketed set (in above example, this means the bracketed set (.) and (\s.) is capturing text as a group that can later be referenced by a $n where ‘n’ is the number of the bracketed group in the sequence you’re referencing. Meaning that, again, if there are two bracketed groups in ilham’s example, it is the second group you want to reference - the (\s.*) - making the n a 2. So, $2.
This regex feature that Emmanuel enabled is SOOOO powerful in respect of the find and replace.
Thank you so much @scriptschool and @ilham.hafizovic! Those explanations were extremely helpful. Really appreciate it and am looking forward to using this.
This doesn’t appear to be solved. The “solution” leaves a space in front of the last name, and no first name solution has been presented. (my earlier one had the same problem of leaving a space)
None of the expressions on this page or the Stack Overflow link helps what is asked here - extract John from John Doe. I found one that works well. Here it is ^([\w-]+)
Sharing this here hoping to help someone down the line. Here’s the simplest methods.
Get first name? Input User’s Value: extract with regex [Enter: ^\w+ ]
Get the last name? Input User’s Value: extract with regex[Enter: \w+$ ]
FYI. If the user enters 3 Names (first, Mid, Last) - the middle one is ignored.
If you want to capture Middle name on its own use the following: (?:[ ])(\w+)*
First + Middle name: ^\w+ \w+
Middle + Last: \w+ \w+$
No need for the brackets or the space in front of ‘:’ btw. You can either use save in database off of one field or you can use to extract full name from database.
To give anyone reading this thread an alternative to regex (this is probably the actual simplest method, but it didn’t exist back when this thread was doing its thing), use Bubble’s :split by operator, split by a space character, and get the first item (or get the last item, if you want the last name).