http://qs1969.pair.com?node_id=376418


in reply to Regular Expression Question

Note that a question mark after a quantifier ({2}?) does not mean optional, but rather non-greedy. You need to put parens around the sub-expression to make it optional:
/^(\d{6}\.?(?:\d{2})?\w?$/;
If the optionals aren't independent, you may need to nest them:
/^(\d{6} #leading digits (?:\.? #if dot, then (?:(?:\d{2})? #if two digits, then \w?)))$/x; #maybe a character
Note the use of anchors, to prevent matching part of the name.

We're not really tightening our belts, it just feels that way because we're getting fatter.