Cut piece from string of api result

I have an api which returns a field which is six characters long, ie. abcdef . I need to use the string but cut in half… I need abc and def… How do I take the result and split like this?

Have you tried using “truncate to …” to get the first three, then do “merge with” and another “truncate to …” for the last three?

Using the method above (or some iteration of it), you should be able to accomplish what you’re after.

I am trying to truncate a value returned from an api field to display in a dropdown; however, truncate is not showing as an option in my choices?

Anyone have an idea?

Do a Google Search for the Regex expression to extract the first ‘n’ characters and the last ‘n’ characters. There are lots of Regex expressions written by others that you can just copy and paste. This is a great site to test an expression on

There is a tutorial that takes you step by step to do exactly what you want here then you simply select ‘extract with Regex’ and paste the appropriate Regex expression.

Can you post a link to your editor? If not, I would guess that you need to store the result of the API call into a state, so that it becomes a text string. You might create a state attached to the page itself, and then set the value of the state equal to the the API request you are making in your screenshot. Instead of calling the API directly int the dropdown, try calling that state and you may be able to use “truncate” combined with “merge with” since you are manipulating a page state rather than the API response itself…Bubble is particular in that way sometimes.

Otherwise, you could use the use both regex and “merge with” the results, or figure out a way to combine both of the expressions below into a single regular expression:
Regex for removing first 3 characters: (^[\s\S]{0,3})
Regex for removing last 3 characters: (...)$

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.