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

Using RegEx to find a number in a string; I'm one off

WanderNotLost
5 - Atom

I've read through the RegEx mastery article, which has been very helpful, bit I've hit a wall.  I'm trying to get quantities out of a text string, and it works for some entries, but not all.  Particularly, where it doesn't work, it truncates the leading number.   Can someone make a recommendation on where I'm going wrong with the parse and how I can correct for it?

 

Parse showing $1 in the first condition, and $2 in the second

(^\d+)|(^.*\s*)(\d+)

 

Data

String to parseDesired outcomeActual outcome
24 sets per case2424
6CS66
Widgets 1/CS11
Many Widgets 20/CS200
Few Widgets -20/Case200

 

 

5 REPLIES 5
MarqueeCrew
20 - Arcturus
20 - Arcturus
In your case, there is only one number set in each input.

Regex_Replace([field],"\D","")

Will remove all other text.

Cheers,

Mark
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
WanderNotLost
5 - Atom

Thanks Mark. Really appreciate the prompt reply!  That works perfectly, as you pointed out, when there is only number.

 

Do you have any suggestions on what to do if there are multiple number sets in each input, but I'd always want to grab the last number set?  For example, in both instances below, I'd want to return 50?

 

0.5 Parts 50/CS

8.5x11 size 50 box

 

 

MarqueeCrew
20 - Arcturus
20 - Arcturus
".*(\d+).*",'$1'

That will get that last number.

Cheers,

Mark
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
PhilipMannering
16 - Nebula
16 - Nebula

@MarqueeCrew ... Your solution will get the very last digit. If you want the whole number I would do something like,

 

workflowworkflow

Thanks,

P

WanderNotLost
5 - Atom

Spot on, @PhilipMannering !  Thanks so much.  Works like a charm.

 

And thanks again @MarqueeCrew 

 

Support here is awesome, thanks to people like the both of you.

Labels