You can use
^(?:[a-z]{3}d{3}.)?(ca.*)
See the regex demo. To make it case insensitive, compile with re.I
(re.search(rx, s, re.I)
, see below).
Details:
^
- start of string
(?:[a-z]{3}d{3}.)?
- an optional sequence of 3 letters and then 3 digits and a .
(ca.*)
- Group 1: ca
and the rest of the string.
See the Python demo:
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) )
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…