Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Regular expression string : 101/AZ19/500000009/08
1st part : 3 digit no
2nd part : 2 char and 2 number
3rd part : 9 digit no
4th part : 2 digt no
 
Seprator is : /
 
How to write regular expression for above string? 


What I have tried:

Regular expression string : 101/AZ19/500000009/08
1st part : 3 digit no
2nd part : 2 char and 2 number
3rd part : 9 digit no
4th part : 2 digt no
 
Seprator is : /
 
How to write regular expression for above string?
Posted
Updated 14-Mar-19 1:47am

A digit is \d. A repetition can be implemented using {N} (meaning that a char or group must be repeated N times). With that, your regex becomes:
^\d{3}/[A-Z]{2}\d{2}/\d{9}/\d{2}$
Test it here: Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
C#
string regex = @"^\d{3}/[A-Z]{2}\d{2}/\d{9}/\d{2}$";
Note the @ before the string; it makes the string a verbatim string literal so you don't have to escape the backslashes.
 
Share this answer
 
v2
Comments
Maciej Los 14-Mar-19 7:31am    
5ed!
Thomas Daniels 14-Mar-19 7:32am    
Thank you
Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900