using 'or' with lookbehind assertions python regexes

57 views Asked by At

I am trying to create a mandatory lookbehind/ahead amongst a few options, to split names of a namespace. I have:

(?<=^)|(?<=[=*%&^|<>,.(){}[\]'"\s])\w+(?=[=*%&^|<>,.(){}[\]'"\s])|(?=$)

The way I read it is "if there's a word with the beginning of a line or one of these splitter characters behind it, AND an end of line or splitter character after it, it's a name for the namespace"

But when ran with:

dict['key']

It grabs the key part, not the dict. This is baffling, because it accepts the or part of after the word, but not before. What should be changed to grab dict first, then key? Thank you

0

There are 0 answers