Why in python if we use 2 bracket within character class without escape them if match [] but not ] or [ :
>>> re.search(r'[[]]','[]').group()
'[]'
>>> re.search(r'[[]]','[').group()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
But if we escape them it will work as expected :
>>> re.search(r'[\[\]]','[').group()
'['
>>> re.search(r'[\[\]]',']').group()
']'
], it consider this as a the end of char class. So we have ([[]=[) + (]=]) which inturn matches[]but fails to match[because it expects another][][](it works because empty character class is not allowed and the first closing bracket is seen as a literal character)