Alteryx Designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
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
15 - Aurora
15 - Aurora

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

DataNath
14 - Magnetar

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
15 - Aurora
15 - Aurora

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

DataNath
14 - Magnetar

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
15 - Aurora
15 - Aurora

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

grazitti_sapna
16 - Nebula

@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
Alteryx

@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