Question

Regex problem


Badge +2

Hi i want regular expression for the format e.g. JXN-12345-1, JXN-12875-2, ALA-3165-0 etc the values changes every time 
I’m using regular expression that is 
But it gives me False result(it gives me result that is not in this format) Please someone guide me where is my issue, how to resolve that issue
 


 

 


2 replies

Userlevel 1
Badge +3

From the examples you’ve mentioned (JXN-12345-1, JXN-12875-2, ALA-3165-0) the Regex you are using is ^[A-Za-z]{3}-\d+-\d$.

The format you want looks like : 3 alphabets - any number of digits - single digit. You can add {1} for the last digit. ^[A-Za-z]{3}-\d+-\d{1}$$

If it doesn’t resolve, please give an example of false result which you are getting and don’t want.

Userlevel 5
Badge +9

@Aima Arif 

Try using the following:

^[A-Z]{3}-\d{4,5}-\d{1}$

 

Regards

Reply