Thanks for the suggestions. This seems to do the trick: match = "('b[0-1zZ\?]*)|('o[0-7zZ\?]*)|('h[0-9a-fA-FzZ\?]*)|(\b(([0-9]+\.?[0 -9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)\b"; The numbers preceding the single quotes are actually picked up as separate constants from the parts beginning with single quotes, which is a bit counterintuitive, but it works.