Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Remove character Before , After & in between the String and add _ in between the string

AKPWZ
8 - Asteroid

I have a string field that looks like this "0.HTTP.2.WebText"  (a JSON_Name field).

 

And I want to remove the unwanted character using regex or any other formula in my workflow to achieve the output.

The output should look like this - "HTTP_WebText".

Any idea how to solve this, please? Thanks.

 

20 REPLIES 20
AKPWZ
8 - Asteroid

HI @Jean-Balteryx 

 

This is what I want as an output: 

 

TCP

HTTP

Loop_Response

WEB_WebText_Wire

WEB_WebText_Wire_Net

Jean-Balteryx
16 - Nebula
16 - Nebula

Have you tried the formula I sent you the message before ? It should return that result.

AKPWZ
8 - Asteroid

HI @Jean-Balteryx 

I checked just now, it's working fine but say if a string has a numeric number in between or say just before or after the string it will not give the desired output.

 

For example:

 

0.WEB4 => WEB_  (But the desired output should be -> WEB)

1.WEB7TCP => WEB_TCP (But the desired output should be -> WEB7TCP)

 

"0.Loop.1.Response56" => Loop_Response_ (But the desired output should be -> Loop_Response56)

"0.WEB.2.Web7777Text.3.Wire33" => WEB_Web_Text_Wire_ (But the desired output should be -> WEB_Web7777_Text_Wire33)

 

 

So here it's removing numbers and appending the _ with string. So what we can do in these conditions.   

Thanks

Jean-Balteryx
16 - Nebula
16 - Nebula

Here it is : 

 

REGEX_Replace(REGEX_Replace(REGEX_Replace([Field1], "\.\d\.", "_"), "\d\.", ""), "^\d*([\l\u]*?)\d*$", "$1")
atcodedog05
22 - Nova
22 - Nova

Hi @AKPWZ 

 

Try the below formula

 

 

REGEX_Replace(
REGEX_Replace([Field1], "\.\d+\.", "_"),
"^\d\.", "")

 

 

Workflow:

atcodedog05_0-1627567345470.png

 

Hope this helps : )

 

AKPWZ
8 - Asteroid

Hi @atcodedog05  thank you for teaching me and helping me to clear my doubts.

I used your regex and found one issue that if starting numbers are in 2 digits or more then it's failing.

 

For Ex:

10.PeopleID1 => 10.PeopleID1 (But the desired output should be => PeopleID1)

11.WEB7TCP5 => 11.WEB7TCP5 (But the desired output should be => WEB7TCP5)

 

Hi, @Jean-Balteryx thank you for your big help and for teaching me regex.

I tried your regex and found one issue that it removing the last integer from a string.

 

For Ex:

10.PeopleID1 => PeopleID (But the desired output should be => PeopleID1)

11.WEB7TCP5 => WEB7TCP (But the desired output should be => WEB7TCP4)

 

Thank you! 🙂

Jean-Balteryx
16 - Nebula
16 - Nebula

You can add a + next to the second \d in @atcodedog05 RegEx and it should be fine! 

atcodedog05
22 - Nova
22 - Nova

Hi @AKPWZ 

 

Please try this

 

REGEX_Replace(
REGEX_Replace([Field1], "\.\d+\.", "_"),
"^\d+\.", "")

 

 

Workflow:

atcodedog05_0-1627582025448.png

 

Hope this helps : )

 

AKPWZ
8 - Asteroid

Yes it's working absolutely fine now 🙌 thank you @Jean-Balteryx 🙂
Thank you @atcodedog05 🙂

atcodedog05
22 - Nova
22 - Nova

Happy to help : ) @AKPWZ 

 

Please do not forget to mark our helpful replies as solution 🙂

Labels