I read about regex at https://medium.com/tech-tajawal/regular-expressions-the-last-guide-6800283ac034 but am having trouble trying to do something very simple.
s = re.compile('(norm|conv)[.][0-9]')
for k,v in densenet_state_dict.items():
print(k)
print(s.findall(k))
It is supposed to print something like norm.2
but it is only detecting norm or conv in my output, not the period nor the digit.
module.features.denseblock4.denselayer16.norm.2.running_mean
['norm']
module.features.denseblock4.denselayer16.norm.2.running_var
['norm']
I even tried '(norm|conv)\.[0-9]'
. Am i missing something very important?
EDIT: The minimum working example
module_type = re.compile('(norm|conv)\.[0-9]')
module_name = "module.features.denseblock4.denselayer16.conv.2.weight"
print(module_name)
print(module_type.findall(module_name))
prints
module.features.denseblock4.denselayer16.conv.2.weight
['conv']