1

I just after some help constructing a regular expression check on the following sequence in C#. I need to ensure the value entered matches the following format.

NNNNCCCCCCCCNNNNNNN

2000AAAAAAAA0001001

enter image description here

Thanks for any help on this

Brendan

3
  • You have two group of A-Z and Digits (3, 4), what is their difference? Can I assume [4 Digits][A-Z][7 Digits]? Commented Feb 23, 2016 at 22:39
  • What software did you use to draw the diagram? Commented Feb 23, 2016 at 23:09
  • I use FastStone Capture. I have for years to help capture screens from my desktop. It has a simple built in image editor. Brilliant software for a small price. Cant recommend it highly enough Commented Feb 24, 2016 at 23:04

1 Answer 1

1
 [0-9]{4}[A-Z]{4}[A-Z]{4}[0-9]{4}[0-9]{3}

If you want to be able to grab each set as a group for processing you need to add ( ) around each pattern.

 ([[0-9]{4})([A-Z]{4})([A-Z]{4})([0-9]{4})([0-9]{3})

This will allow you to recover each set of characters from the match without having to re-parse the string again. If you need that.

Oh and if the first set of digits cannot start with a zero

[1-9][0-9]{3}[A-Z]{4}[A-Z]{4}[0-9]{4}[0-9]{3}
Sign up to request clarification or add additional context in comments.

2 Comments

OOPS did not pay enough attention this is for C# :).. fixing it.
If you want to allow lower-case letters, use small zs instead of big Zs. Also, does C# allow \d in place of [0-9] like Ruby does?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.