LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unique regular expression to check if a string contains letters and numbers


Darin.K wrote:

2.  Using my regex helper means I do not even have to worry about it or remembering the exact syntax of any of the posix classes.


What is your regex helper, please?

0 Kudos
Message 11 of 13
(1,018 Views)

https://decibel.ni.com/content/docs/DOC-13698

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 12 of 13
(1,008 Views)

@Darin.K wrote:

Missed the requirements:

 

single regex:

 

^([[:alpha:]]+[[:digit:]]+|[[:digit:]]+[[:alpha:]])[[:alnum:]]*$

 

You either have 1 or more digits followed by 1 or more letters or 1 or more letters followed by 1 or more digits. Once that is out of the way, the rest of the string must be all alphanumerics.  The ^ and $ make sure the whole string is included in the match.

 

(I have not tested this at all, just typed it up hopefully I got all the brackets in the right place).


When I copied your regex and pasted it into a string constant, I got ^([[:alpha:]]+[[:digit:]]+|[[:digit:]]+[[:alpha:]]​?)[[:alnum:]]*$, but the question mark disappears when I paste it into this response.  Weird. 

 

Example_VI_BD.png

 

Anyway, the question mark needs to be a "+" and it'll work.

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 13 of 13
(1,004 Views)