Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need a regular expression satisfying the following condition

eg: A0A 0A0,b2b 2c3,r4r 3e3

Alphabet digit Alphabet space digit Alphabet digit

A->Alphabet
0->digit
Posted

Following would do,

(\w\d\w)( )(\d\w\d)

Sample code here,

String pattern = @"^(\w\d\w)( )(\d\w\d)$";
       String input = "A0A 0A0";
       Regex objRegEx = new Regex(pattern);
       MatchCollection result = objRegEx.Matches(input);
       if (result.Count>0)
       {
           for (int i = 0; i < result.Count; i++)
           {
               Response.Write(result[i].Value+"<br/>");
           }
       }


Hope it helps ,

Thanks
Arindam D Tewary
 
Share this answer
 
There are numerous regex builder tools, you can use any one.
try this:
Regex Builder[^]
 
Share this answer
 
You can use Expresso to help write Regex's:

http://www.ultrapico.com/Expresso.htm[^]

Nick
 
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