Alteryx Designer Desktop Discussions

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

parse string using other strings

Mikis
8 - Asteroid

Hello,

 

I have a list of strings with an underscore seperator like the following:

ftThreefinalgrps_brd4_co10
ftif5_co10
ftqn5_bra1

I also have a list of "identifiers", that tell me what each part of the string means.

please note that the number of identifiers and their name is variable

br

ft

co

 

The goal is to parse the string using the identifiers.

Using my first variable, I want to find everything after "br" and before the underscore (if there is any), in this case "d4".

Then I want everything after "ft" and before the underscore, being "Threefinalgrps"

Finally, I want everything after co and before the underscore, so "10"

 

My ideal final result would be:

variableftbrco
ftThreefinalgrps_brd4_co10Threefinalgrpsd410
ftif5_co10if5 10
ftqn5_bra1qn5a1 

 

Does anyone have a suggestion on how to start?

 

Thanks!

Mikis

14 REPLIES 14
Mikis
8 - Asteroid

I think I got it :)

 

Could it be that

?=

should have been

?:

I changed it to the below, and it seems to be working (even though I don't know why, I just read that an umarked group was defined by (?: ) and I somehow think you're doing that?

 

REGEX_Replace(
   [variables],
   ".*?((?:^|_)" + [dimensions] + "([^_]+))?.*?",
   "$2")

 

jdunkerley79
ACE Emeritus
ACE Emeritus

No I was trying to do a look behind but lets make it simpler:

REGEX_Replace(
   "_" + [variables],
   ".*?_(" + [Field1] + "([^_]+))?.*?",
   "$2")

This requires an _ before the field name and then gets around the start by just prefixing the string!

 

My quick check seems to show this should work

Mikis
8 - Asteroid

Hm, now everything seems to Match (only the real match removes the dimension prefix).

i do understand what you're trying to do and it's really resourceful

But my above formula does what I was hoping for, do you think there are issues to it?

 

issue.PNG

jdunkerley79
ACE Emeritus
ACE Emeritus

Yep, yours should work perfectly.

 

Adjusted mine and think it should work as well finally!

REGEX_Replace(
   "_" + [variables],
   ".*?((?<=_)" + [Field1] + "([^_]+))?.*?",
   "$2")
Mikis
8 - Asteroid

Works like a charm!

Labels