Regular expression negative lookbehind of non-fixed length

前端 未结 2 833
青春惊慌失措
青春惊慌失措 2021-01-12 10:18

As the document goes:

This is called a negative lookbehind assertion. Similar to positive lookbehind assertions, the contained pattern must only match

2条回答
  •  一个人的身影
    2021-01-12 10:52

    Instead of using Negative Lookbehind, you can use Negative Lookahead with balanced braces.

    ,(?![^{]*\})
    

    For example:

    >>> re.findall(r',..(?![^{]*\})', 'a1,a2,a3,a4,{_some_unknown_length,a5,a6,a7}')
    [',a2', ',a3', ',a4']
    

提交回复
热议问题