Unlike search()
, Python's match()
method automatically anchors the match at the beginning of the string. That means you're trying to match the literal string decimal(
before the beginning of the string, which of course will always fail.
But as Jared pointed out, you don't need lookbehind for this anyway. In fact, lookbehind should be the last tool you reach for, not the first.
Here's a slightly modified version of Jared's regex:
r'\bdecimal\(\s*(\d+\s*,\s*\d+)\s*\)'
The most important change is the addition of the word boundary (\b
) to prevent it matching things like snarfdecimal(4,1)
. If you really have to use match()
instead of search()
, you can "pad" the regex with .*?
, forcing it to consume the intermediate characters:
r'.*?\bdecimal\(\s*(\d+\s*,\s*\d+)\s*\)'