Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Adding a hyphen to a string based on certain criteria

ccano
8 - Asteroid

Hello Everyone, I am attempting to add a hyphen to an array of strings within my data. 

 

In other words,I need to randomly introduce a hyphen to some fields of medications based on their alphabetical sequence. 

 

Some medications start with "ei", hence I have to place a hyphen after the "i". Hence, I need the field to look like this (excluding the quotes) "ei-dxph"

 

Medication NameConditionExpected Results
eidxphHyphen after " ei "ei-dxph
daxphHyphen after "d"d-axph
oexphHyphen after "oe"oe-xph
9yvhpkHyphen after "number and Letter"9y-vhpk
fhyqx Hyphen after " f "f-hyqx
5 REPLIES 5
AnthonyJ
Alteryx Alumni (Retired)

Hi, see attached, using a batch macro and a little RegEx to find the pattern of interest and create a new column w/ Med Name, hope this helps....

 

AJ

dhtay
8 - Asteroid

@ccano 

Here's my solution.

 

I generated a list of prefixes that need to have hyphens added behind them. Then, I used Find Replace with "beginning of string" setting to replace these prefixes with themselves but with an added hyphen.

AnthonyJ
Alteryx Alumni (Retired)

Great! If you always know what the text will be that needs to be parsed then the Find Replace is perfect, if not and it needs to be more dynamic, use RegEx

dhtay
8 - Asteroid

@AnthonyJ 

Thanks! I thought regex would be better too, but I couldn't find a way to apply regex replace at just the beginning of the string. Your use of regex parse solves the problem.

ccano
8 - Asteroid

Thanks for the quick feedback Anthony! 

 

Unfortunately, my version of alteryx is not up to date (company has to update it for us). Would you mind displaying a screenshot of the solution if possible? 

Labels