Assign one material to multiple objects via Python
for the python specific stuff

objects = bpy.data.objects

material_01 = bpy.data.materials['some_named_material']
for obj in objects:
    if '_A_' in obj.name:
        obj.data.materials[0] = material_01

Si = 1
for obj in objects:
    if '_B_' in obj.name:
        obj.data.materials[0] = material_02
        Si+=1
        if Si == 15:
            break


You might have to do additional sorting of all objects that contain those strings.