Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

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

REGEX conditional formula

gwiz
8 - Asteroid

In a field, I'd like to extract text before first underscore if just one underscore. and if there are two underscores, extract text between the two. I can't seem to get a regex formula to work.

 

Example:

aywkhqeq_abcde_weyfb

abc_weyw

 

Is there a regex that can match abcde in the first one and abc in the second?

3 REPLIES 3
fmvizcaino
17 - Castor
17 - Castor

Hi @gwiz ,

 

Yes, there is a formula.

Use the parse method and the following expression: .*?([^_]+)_[^_]+$

 

Let me know if that works for you.

Best,

Fernando Vizcaino

MarqueeCrew
20 - Arcturus
20 - Arcturus

@gwiz ,

 

I simplified the conditions and constructed this formula:

 

IF REGEX_COUNTMATCHES([Field1],"_") = 1 THEN
	REGEX_Replace([Field1], "(.*?)_.*", '$1')
ELSE
	REGEX_Replace([Field1], ".*?_(.*)_.*", '$1')
ENDIF

 

Cheers,


Mark 

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
gwiz
8 - Asteroid

@MarqueeCrew 

@fmvizcaino 

 

Both those approaches worked. Appreciate the responses!

 

Cheers

Labels