Click here to Skip to main content
13,900,823 members
Rate this:
 
Please Sign up or sign in to vote.
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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[^]
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.
   
v2
Comments
Maciej Los 14-Mar-19 7:31am
   
5ed!
Thomas Daniels 14-Mar-19 7:32am
   
Thank you
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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[^]
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190306.1 | Last Updated 14 Mar 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100