In my code, I use four four regex conditions but it is too long, so is there simple or general method can combine these conditions?
I tried to r'[(abc|def)+^((?!(xyz|efg)).)*$^.*[^,|.]$]{1,10}$'but it didn't work...
s_l = ['abcabcabcabc', 'defdef.', 'sssssss', 'def', 'def,', 'xyzabc,', 'efgdefefg']
for idx, str_item in enumerate(s_l):
if (re.match(r'(abc|def)+', str_item) # find abc or def in str
and re.match(r'^((?!(xyz|efg)).)*$', str_item) # find xyz and efg not in str
and re.match(r'^.*[^,|.]$', str_item) # comma not in the end of str
and re.match(r'^[a-zA-Z]{1,10}$', str_item)): # find length of str smaller than 10
print(idx, "True")
else:
print(idx, "False")