The look behind target is never included in the match - it's supposed to serve as an anchor, but not actually be consumed by the regex.
The look behind pattern is only supposed to match if the current position is preceded by the target. In your case, after matching the "foo" in the string, the current position is at the "=", which is not preceded by a "=" - it's preceded by an "o".
Another way to see this is by looking at the re documentation and reading
Note that patterns which start with positive lookbehind assertions will never match at the beginning of the string being searched;
After you match the foo
, your look behind is trying to match at the beginning of (the remainder of) the string - this will never work.
Others have suggested regexes that may probably serve you better, but I think you're probably looking for
>>> re.search('(foo)(=(bar))?', 'foo=bar').groups()
('foo', '=bar', 'bar')
If you find the extra group is a little annoying, you could omit the inner "()"s and just chop the first character off the matched group...