import re
rx = r"^(?:[a-z]{3}\d{3}\.)?(ca.*)"
strs = ["dal001.caxxxxx.test.com","caxxxx.test.com"]
for s in strs:
m = re.search(rx, s)
if m:
print( m.group(1) )
aW1wb3J0IHJlCnJ4ID0gciJeKD86W2Etel17M31cZHszfVwuKT8oY2EuKikiCnN0cnMgPSBbImRhbDAwMS5jYXh4eHh4LnRlc3QuY29tIiwiY2F4eHh4LnRlc3QuY29tIl0KZm9yIHMgaW4gc3RyczoKICBtID0gcmUuc2VhcmNoKHJ4LCBzKQogIGlmIG06CiAgICBwcmludCggbS5ncm91cCgxKSAp