community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

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

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

Alteryx Partner

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

 

 

Alteryx Certified Partner
Alteryx Certified Partner
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 reboot. Order shall return.
Alteryx Partner

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

 

 

Alteryx Certified Partner
Alteryx Certified Partner
".*(\d+).*",'$1'

That will get that last number.

Cheers,

Mark
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and reboot. Order shall return.
Highlighted
Alteryx Certified Partner

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

 

Last Number - Capture.PNGworkflow

Thanks,

P

Alteryx Partner

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