Select objects with name sequence
bpy.ops.object.select_pattern
As mentioned in your previous question re the operator script  Script is selecting all the objects (unwanted) there is already a pattern matching operator, bpy.ops.object.select_pattern which uses Unix file token matching.  See no need to &quot;reinvent the wheel&quot; and write another, which so far has no extra functionality.  Here is quick run down on how it works. (The code of the operator is available in bl_operators/object.py.)
&gt;&gt;&gt; bpy.ops.object.select_pattern(
select_pattern()
bpy.ops.object.select_pattern(pattern=&quot;*&quot;, case_sensitive=False, extend=True)
Select objects matching a naming pattern

options to extend the selection, and a case insensitive match.
&gt;&gt;&gt; import fnmatch
&gt;&gt;&gt; fnmatch.fnmatch(
fnmatch(name, pat)
Test whether FILENAME matches PATTERN.
Patterns are Unix shell style:
*       matches everything
?       matches any single character
[seq]   matches any character in seq
[!seq]  matches any char not in seq
An initial period in FILENAME is not special.
Both FILENAME and PATTERN are first case-normalized
if the operating system requires it.
If you don't want this, use fnmatchcase(FILENAME, PATTERN).

So for example sake will pinch
&gt;&gt;&gt; txt = {&quot;US40.004&quot;, &quot;US40.005&quot;, &quot;US41.001&quot;, &quot;US51.006&quot;, &quot;US-009.009&quot;, &quot;US-009.010&quot;, &quot;US-015&quot;, &quot;US-016&quot;, &quot;USA&quot;, &quot;USADOT&quot;}

make a pattern, Case sensitive, any name starting with &quot;US&quot; but not having  an uppercase character as third character. then end with anything
&gt;&gt;&gt; pattern = &quot;US[!A-Z]*&quot;
&gt;&gt;&gt; for t in txt:
...     t, fnmatch.fnmatchcase(t, pattern)
...     
('US-009.009', True)
('US40.005', True)
('US41.001', True)
('US51.006', True)
('US-016', True)
('US-009.010', True)
('USA', False)
('USADOT', False)
('US-015', True)
('US40.004', True)

Looks about right, so a call with instead object names matching the sample list
bpy.ops.object.select_pattern(pattern=&quot;US[!A-Z]*&quot;, case_sensitive=True)

in object mode will select all objects denoted True above
To clarify, re the commentary below, it is not necessary to use the operator could (thought this was implied TBH) instead
for ob in scene.objects:
    ob.select_set(fnmatch.fnmatchcase(ob.name, pattern)) # match case

Re setting the active object. If the context object is no longer selected, or None and you wish it to be one of the selected
if context.selected_objects and context.object not in context.selected_objects:
    context.view_layer.objects.active = context.selected_objects[0]

ie If the active object is set and selected probably don't want to randomly change it to another of the selected objects.  (BTW most selection operators do not set the active object)