regex - Regular expression grouping with lookaheads (in Python) -
i'm modifying regular expression extract group of group matches, 'supergroup' not return composite matched string expected.
the string match of form:
/dir/somestring-w0.12+345.raw.gz
and regex i'm using:
/dir/ (?p<super> (?p<name>.*?) (?=(?p<modifier>-w\d\.\d{2}[+-]\d{3})?\.(?p<extension>raw\.gz|root)$) )
i'm getting following results named groups:
modifier: '-w0.12+345' super: 'somestring' name: 'somestring' extension: 'raw.gz'
while expecting
super: 'somestring-w0.12+345.raw.gz'
the grouping of subgroups has worked me, not time, , cannot understand why.
hope give me hint.
note: explanation of regex can found in (matching specific substring regular expressions using awk)
the group super
matches same text group name
matches, because lookahead assertion doesn't contribute actual characters match (that's why they're called "zero-width assertions").
to desired result, remove lookahead assertion:
/dir/ (?p<super> (?p<name>.*?) (?p<modifier>-w\d\.\d{2}[+-]\d{3})?\.(?p<extension>raw\.gz|root)$ )
Comments
Post a Comment