I am trying to run a regular expression in VBA code that uses Microsoft VBScript Regular Expressions 5.5 (should match the JavaScript regular expression).
Regular expression: ^[0-9A-Z]?[0-9A-Z]{3}[A-Z]?([0-9A-Z]{6})-?([0-9])?$
Input: X123A1234567
Match:123456
The six characters that interest me give a good match 123456, ignoring the last digit. Fine. (The check digit is fixed, but this is not a serious problem for me.)
But when the BOTH optional parts go away (they are optional), the match captures the last digit.
OK:
Input: 123123456
Match:123456
No alpha, no check digit. Good coincidence.
OK
Input: 123A1234567
Match:123456
, , , - 123456.
: X1231234567
: 123456
, , , - 123456.
BAD
: 1231234567
: 234567
, , 234567.
http://www.regular-expressions.info/javascriptexample.html http://www.regular-expressions.info/vbscriptexample.html.
? , ? , .
: ( ). .
UPDATE: , (!):
: ^[A-Z]?[0-9]{3}[A-Z]?([0-9]{6})-?([0-9])?$