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

REG_EX Formula to pull defined length in string field

almartinez
6 - Meteoroid

Hello Team,

 

I'm tryting to retrieve an specific length for digits in a string field, I'm using a Reg_Ex Formula to do this [ Regex_replace([field1],"[^\d]+"," ") ] and I'm getting almost what I need since with the formula I'm retriving only digits from the field however I exactly need to pull only the values with 7 digits only which are separeted by " ". is there any way to this more friendly?

 

Field 3 should be my desired result.

 

Screenshot_1.png

 

 

 

2 REPLIES 2
rarmstrong
8 - Asteroid

I would use the RegEx tool and Parse. You would keep RegExOut2 as your results.

 

 capture.PNG

 

 

Capture2.PNG

Claje
14 - Magnetar

Try the following formula:

Regex_replace([Field1],".*\s([\d]{7})(?:$|[\s]+).*","$1")

This will look for any 7 digit value that is prefaced by a space and then immediately preceded by either a space or an end of line character.  The ([\d]{7}) is a marked group, looking specifically for 7 digits, and is also the corresponding "$1" in the "replace value" of the formula.  This leaves us with only the matching number.


Labels