How the document goes:
This is called a negative lookbehind statement. Like the positive lookbehind statements, the contained pattern should only match strings of some fixed length .
So this will work, the intent should match anyone ,outside {}, but not inside {}:
In [188]:
re.compile("(?<!\{)\,.").findall('a1,a2,a3,a4,{,a6}')
Out[188]:
[',a', ',a', ',a', ',{']
this will work, in a slightly different request:
In [189]:
re.compile("(?<!\{a5)\,.").findall('a1,a2,a3,a4,{a5,a6}')
Out[189]:
[',a', ',a', ',a', ',{']
In [190]:
But if the request 'a1,a2,a3,a4,{_some_length_not_known_in_advance,a6}', according to the document, the following actions will not work as intended:
In [190]:
re.compile("(?<![\{.*])\,.").findall('a1,a2,a3,a4,{a5,a6}')
Out[190]:
[',a', ',a', ',a', ',{', ',a']
Any alternative to achieve this? Is a negative approach wrong?
, lookbehind ( )?