Alteryx Designer Desktop Discussions

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

Regex: any 10 digit number preceded by "#" or "# "

PabloDanielovich
7 - Meteor

I have a field that contains text and an account number embedded in the text.  for example

 

blah bla blah testing ACCT # 3402058931 \bla \ABC\203499\ blah blah

The problem is the string that precedes the account number and is supposed to be the identifier,  sometimes contains typos:
it varies: "ACCT # ", "ACCOUNT#", "AC#" (with or without spaces).  so to parse it out I'm thinking to match any 10 digit number that is preceded by either "# " or "#",  not sure I want to include all of the possible variations. 
So far I have (\d{10}), which will match any 10 digit number (this should work 95% of the time, but it would be good if I could improve it.

 

5 REPLIES 5
MarqueeCrew
20 - Arcturus
20 - Arcturus
Regex_replace([field],".*(\d{10}).*",'$1')

That should get it.
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
PabloDanielovich
7 - Meteor

Thanks Marquee Crew
could you explain that expression?  how does that make sure the account number is preceded by "#" or "# "?  
is the $1 basically saying that we're replacing the entire field value with just the first matched group?   

MarqueeCrew
20 - Arcturus
20 - Arcturus
Regex_replace([field],"(.*#|.*#\s)(\d{10}).*",'$2')

Group 1 is
Any characters followed by a # or
Any chapters followed by a # followed by a space.

Group 2 is
10 digits

Followed by anything

The replacement is group 2

Cheers,
Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
PabloDanielovich
7 - Meteor

Awesome.  Thank you

 

 

MarqueeCrew
20 - Arcturus
20 - Arcturus
You're quite welcome.
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
Labels