Alteryx Designer Desktop Discussions

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

Counting the number of instances in a string where instances are of varying lengths

TA_MBC
6 - Meteoroid

Hi,

 

I have a string of marks which are of varying lengths and contain different symbols.  I have used REGEX_CountMatches([field],'symbol',1) to count the number of times the symbol is in the string, however the symbol can be repeated for any number of times, stop and then start again.  I need to count the number of times the symbol starts...

 

example:

 

xxxxxxYxxxxYYYxxxYYxxxxxxYYYYY

 

in the string above the RegEx function will give me 11 Ys, which is great but I also need to get an answer of 4 for this example.

 

Any suggestions?

 

Thanks.

2 REPLIES 2
DavidSkaife
13 - Pulsar

Hi @TA_MBC 

 

I'm assuming you're using Regex_CountMatches? A simple tweak to the code is required by adding + after the Y:

 

REGEX_CountMatches([field1], 'Y+')

 

 

You then get this output:

 

DavidSkaife_0-1675246814949.png

 

The + denotes to look for one or more instances of Y

 

TA_MBC
6 - Meteoroid

That's perfect! thank you :)

Labels