Alteryx Designer Desktop Discussions

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

Regex to check if string is of exact length 7

shobhit_gupta
7 - Meteor

I have a requirement where I need to check if a first character of a string is an alphabet (a-z or A-Z), rest all characters should be numbers (0-9) and string length should be exactly equal to 7. 

I am using regex tool to achieve this and used this expression: ([A-Za-z]+)([0-9]+)

With this, I am able to solve only the first two requirements but not the third one (length = 7). Can't wrap my head around this. Any suggestions are welcome. Thanks in advance.

 

6 REPLIES 6
binuacs
20 - Arcturus

@shobhit_gupta One way of doing this with the Regex Tokenize method

 

binuacs_0-1673432622746.png

 

ShankerV
17 - Castor

Hi @shobhit_gupta 

 

There is 2 ways to get result.

You can use Formula tool with length([Field]).

 

Many thanks

Shanker V

OllieClarke
15 - Aurora
15 - Aurora

Hey @shobhit_gupta Try this:

[A-Za-z]\d{6}

This states that the first character is a letter and the next 6 are numbers. As Regex Match always looks at the full string, this will only be true if the string is 7 characters long

 

Hope that helps,

 

Ollie

 

(if you want a more concise RegEx then:

\l\d{6}

with case insensitivity on will do the same thing)

FinnCharlton
13 - Pulsar

Maybe use a formula or filter tool: you can use a REGEX_MATCH function to check the regex, then add "and length([String])=7"

Felipe_Ribeir0
16 - Nebula

Hi @shobhit_gupta 

 

One way of doing this

 

(^[A-Za-z])([0-9]{6})

 

Felipe_Ribeir0_0-1673432794434.png

 

ShankerV
17 - Castor

Hi @shobhit_gupta 

 

The second solution is with regex.

 

ShankerV_1-1673432947609.png

 

 

^([A-Za-z]{1}\d{6})

 

ShankerV_0-1673432927490.png

 

 

Many thanks

Shanker V

 

 

Labels