Skip to content

Thanks Darren...Show us your-Regex!

Wed Oct 01 2003

The place that I work uses what we call index numbers (they're not really numbers per se...) that are based on API numbers (which are usually numbers) for check shot velocity surveys. I'm working on a project that will validate these and I thought that it would be well suited for Regex since it's going to be text validation and there are rules in place for these Index “numbers”.


So first I go to www.regexlib.com and see what that might have to get those Regex juices flowin. Then I thought about the Regex that I need to write and wrote it out as the rules should apply:



  1. Start at the beginning of a string.

  2. Match exactly 2 digits.

  3. Match exactly 1 letter (uppercase).

  4. Match no less than 3 but no more than 4 digits.

  5. Optionally match 1 or 2 letters (uppercase).

  6. End of string.

So, I fired up Darren Neimke's RegexSnippets which I have sitting in my C:\Tools folder for just such an occasion, and this is what I came up with:


^\d{2}[A-Z]{1}\d{3,4}([A-Z]{1,2})?$


And much to my surprise it worked the first time running! Very nice. Plus, I was able to save the regex for later using Darren's cool little utility. Added bonus: there was already one expression (8PointFloat) that I needed for a different area. Thanks Darren!

💾 May the source be with you. v3.2.1220