How to make two SPLIT in a variable?

What are you trying to achieve?

In an http request module I am doing a “GET” to retrieve a variable.

This variable needs to be separated because I don’t need all the characters.

While doing some research here in the community I saw the option of using the “SPLIT” function since the “SUBSTRING” function doesn’t work because this variable never has the same size.

I’ve been trying to separate this variable for days and I can’t do it in any way, I feel like an idiot.

Steps taken so far

So, first I do a “GET” to get the variable.

Now that I have the variable, I created a “SET A MULTIPLE VARIABLES” module
to separate the data.

The problem is that normally the variable comes in this format:

XSRF-TOKEN=eyJpdiI6IjNpMXVsMWl1enBRUUsrejAxWlwva1JBPT0iLCJ2YWx1ZSI6ImlQNEJcLzkyUHRmSVJvNzlTdU5WQ3pnQ24yTFowV3NjUU13VE9PdDFobzVcL1R4d UlQZVZ5MmUySjBZV1VuYU9ZKyIsIm1hYyI6IjAxYjA2NWE4MjNkZGM3Y2IyMWUwNzQ yNjU4Njk1NDI1NTU2NGI0YWIyOTJkYjhlZWM2YjA0ZWJmMDk0ZDU2MmUifQ%3D%3D; expires=Sex, 24-Jan-2025 20:26:18 GMT; Max-Age=21600; path=/

What I need to do is separate it into 2 variables, they should look like this:

First variable:

eyJpdiI6IjNpMXVsMWl1enBRUUsrejAxWlwva1JBPT0iLCJ2YWx1ZSI6ImlQNEJcLzkyUHRmSVJvNzlTdU5WQ3pnQ24yTFowV3NjUU13VE9PdDFobzVcL1R4dUlQZV Z5MmUySjBZV1VuYU9ZKyIsIm1hYyI6IjAxYjA2NWE4MjNkZGM3Y2IyMWUwNzQyNjU4Njk1NDI1NTU2NGI0YWIyOTJkYjhlZWM2YjA0ZWJmMDk0ZDU2MmUifQ%3D%3D

So I need to remove the beginning:

XSRF-TOKEN=

and the end:

; expires=Fri, 24-Jan-2025 20:26:18 GMT; Max-Age=21600; path=/

Second variable:

XSRF-TOKEN=eyJpdiI6IjNpMXVsMWl1enBRUUsrejAxWlwva1JBPT0iLCJ2YWx1ZSI6ImlQNEJcLzkyUHRmSVJvNzlTdU5WQ3pnQ24yTFowV3NjUU13VE9PdDFobzVcL1R4 dUlQZVZ5MmUySjBZV1VuYU9ZKyIsIm1hYyI6IjAxYjA2NWE4MjNkZGM3Y2IyMWUwNz QyNjU4Njk1NDI1NTU2NGI0YWIyOTJkYjhlZWM2YjA0ZWJmMDk0ZDU2MmUifQ%3D%3D

In this second one, I just need to remove the end:

; expires=Fri, 24-Jan-2025 20:26:18 GMT ; Max-Age=21600; path=/

I managed to do this second one just by using “SPLIT” by putting
“; expires=”

but in the first one I can only remove the beginning OR the end, I can’t remove both.

Screenshots: scenario setup, module configuration, errors



Hi @Thiago_Ferreira, split() function usually generates an array of data. in “item1,item2,item3” separator “,” generates [item1 item2 item3]. In your case, I would tell you to use a regex pattern match to avoid long formula - but it can be hard to configure. If you want to stay with split, you can use get() method to choose n-th index of the array.

For 1st variable : get(split(get(split(text;XSRF-TOKEN=);2); expires);1)

This will get you the token. notice i’m splitting 2 times with different keywords. the problem now is that we have a semicolon in the end. we can’t include the semi-colon in the keyword, because it’ll interact with Make native formula…

For the second variable it’s simpler, just do one get(split(text; expires=);1). I’ll be looking for a solution to remove that semi-colon though. …

Edit : {{get(split(get(split(43.text; “XSRF-TOKEN=”); 1); “; expires=”); 1)}} so this worked to not include the semi-colon either, but in my experience sometimes causes some errors as Make is identifying ; as a native function element.

You saw that I managed to remove the ; using get in addition to it “; expires=”

My problem is only in the first variable.

I tried using what you said, but it didn’t work.


My God, will anyone come to help me, I wanted to solve this so badly =(

Wrap the split() function you use to get your second variable inside a replace(split();XSRF-TOKEN=;"")

That will replace the part you don’t want with nothing

1 Like

It wasn’t like you said, but it gave me an idea that worked.

I decided to create another variable set and use replace and it worked.

Thank you very much!


image

1 Like