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

Count substring if contains number?

yaser
7 - Meteor

Hello!

 

How can I count the number of substrings within a string, which contain numbers?

 

The following is what I am trying to get:

 

AddressCount
Outing Park 69 Oswego St Apt 1R2
Outing Park 69 Oswego St Apt 1R2
Austin Street Apt 8101
O RUBIN COURT APT D71
HAMBLIN CT 23 E MAIN ST APT 1B2
OLNEY ST APT 4171

 

Thanks in advance!! 🙂

4 REPLIES 4
CharlieS
17 - Castor
17 - Castor

I'm not the best at RegEx, but this should do the trick:

 

REGEX_CountMatches([Address],"\s*(\d+)\s*")

 

Use this as the expression in a Formula tool. Example attached. 

yaser
7 - Meteor

This works perfectly!

 

Could you please explain the expression?

 

Thanks!

CharlieS
17 - Castor
17 - Castor

Sure thing!

 

REGEX_CountMatches([Address],"\s*(\d+)\s*")

 

- RegEx_CountMatch( is an expression that counts the matches with [String] as defined by "RegEx" pattern.

- "\s*" is zero or more (*) space character (\s) and "\d+" is one or more (+) digit characters (\d). So the pattern is a digit character with a space on one side or another before another digit character occurs. 

 

This could use some more work because it has trouble with non-sequential digits since the spaces are optional. 

Edit: This works.

REGEX_CountMatches([Address],"\s*(\w*\d+\w*)\s*")

yaser
7 - Meteor

Nice!! thank you very much!!

 

 

Labels