0

I need to check if a XML document contains some software build numbers

normally they're like ######, where:

  • First two characters are numbers

  • Third character is a letter in uppercase

  • last three characters are numbers

Example: 10B329 or 11A465.

But there could be some exceptions, like 8L1 or 11B465a. (if there's another character after the sixth, it's always a letter in lowercase).

I think they're always with a minimum length of 3 characters and a maximum length of 7 characters.

So what could be the best pattern to match? I tried this but it doesn't work since it takes also words...

Dim BuildPattern As String = "<key>[0-9A-Z]*</key>"
Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111

1 Answers1

0

Try this Regex: \d{2}\w\d{3}

You can see a live demo here.

You can add the <key></key> tags too: <key>(\d{2}\w\d{3})<\/key>. This way, your match will be in group 1 of the match. Changed demo.

Note that you should rather use XML parser for this as it's safer and more accurate than working with regex on XML files.

EDIT: Can't help you with the non-standard length though, my knowledge of regexes is still too low. Perhaps you really should try XML parser instead?

Asunez
  • 2,327
  • 1
  • 23
  • 46
  • *But there could be some exceptions, like 8L1 or 11B465a.* and *I think they're always with a minimum lenght of 3 characters and a maximum lenght of 7 characters.* – Wiktor Stribiżew Aug 11 '15 at 09:49