pylogsparser
pylogsparser copied to clipboard
redefinition of group name error
The below example pattern will generate a "redefinition of group name error". Further investigation shows that the fault is in 'get_uncompiled_regexp()' with the following line: regexp = regexp.replace(tag.substitute, named_group) this will cause creating the same group name multiple times in the regex because it will replace the string "PRODUCT" 3 times and will actually create a wrong regex to compile.
the string replacement should be exact, e.g.: regexp = re.sub(r'\b%s\b' % tag.substitute, named_group, regexp) but I guess there are many edge cases where this will not work, so maybe the documentation should point out that in the pattern text one should avoid
<pattern name="ex1"> <text>PRODUCT PRODUCT_VERSION PRODUCT_NAME </text> <tags> <tag name="product" tagType="Anything"> <substitute>PRODUCT</substitute> </tag> <tag name="product_version" tagType="Anything"> <substitute>PRODUCT_VERSION</substitute> </tag> <tag name="product_name" tagType="Anything"> <substitute>PRODUCT_NAME</substitute> </tag> </tags> </pattern>