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 to extract string and number

poojasingh111
6 - Meteoroid

Help me please to create a regex to extract string and number from a string like 906D3829.22 into 906 D 3829.22

So far, I have been able to extract numbers using  [\d.]+ into 906 3829.22

9 REPLIES 9
kathleenmonks
Alteryx
Alteryx

This should work for any number/string/number combination: ([\d]+)([[:alpha:]]+)([\d].+)

 

community_ex.PNG

PhilipMannering
16 - Nebula
16 - Nebula

@kathleenmonks Does that last full stop need to go inside the square brackets?

DataNath
17 - Castor

If you use a formula tool with:

 

Regex_replace([Field], '(\d+)(\D+)([0-9\.]+)', '$1 $2 $3')

 

I believe that should give you the output requested above in a single field. Not at my laptop with an Alteryx install to double check this, though.

PhilipMannering
16 - Nebula
16 - Nebula

@DataNath You don't need to escape that full stop / period.

DataNath
17 - Castor

Thanks for the tip @PhilipMannering! Is that always true when including characters you'd normally escape within a group?

kathleenmonks
Alteryx
Alteryx

@PhilipMannering Good catch. It works as is for this particular case, but the decimal identifies "any single character" so it could result in other characters slipping through. You could change it to: ([\d]+)([[:alpha:]]+)([\d\.]+) to only pick up the decimal. 

PhilipMannering
16 - Nebula
16 - Nebula

@DataNath Oooh.. that's a good question. I think that is the case, yes.

grazitti_sapna
17 - Castor

@poojasingh111, try this if it helps?

 

(\d+)([a-zA-Z]+)(\d.+)

 

grazitti_sapna_0-1655128734685.png

 

grazitti_sapna_0-1655128858906.png

 

 

Thanks!

 

Sapna Gupta
CarliE
Alteryx Alumni (Retired)

@poojasingh111 

 

Use a regex tool and select the parse mode -- input this in

 

(\d+)(\D+)(.+)

 

What this is doing is creating 3 groups

Group 1 - digits up to a non digit char

Group 2 - non-digit character

Group 3 - everything else after group 2

 

Please make sure to mark a solution!

 

Thanks

Carli
Labels