regex - Referencing named groups in look-around (Python 2.x) -
i have pattern matches multiple key/value pairs, , key/value strings can delimited characters, groups of key/value can delimited, not same character . i figured out how allow dynamic delimiters, , restrict same delimiter being used twice. eg: \w+(?p<kv_delim>[:;|])\d+(?p<g_delim>(?!(?p=kv_delim))[:;|])\w(?p=kv_delim)\d(?p=g_delim)? you can view regex101.com example here . , works great, problem comes when using either of 2 named groups in positive look-behind . lets string is foo:1;r:2 the "key/value delimiter" (named group: kv_delim ) : , "group delimiter" (named group: grp_delim ) ; what im trying dynamically match : , ; , in look-around statement, foo<kv_delim> , or bar<kv_delim> . if hard-code delimiters (in look-around), you can see works . if try reference named-group kv_delim within look-around statement, you can see throws errors . error: subpattern references not allowed within lookbehind assertion ...