Replace match
with search
. match
matches from the start of a string; search
matches anywhere within the string.
>>> import re
>>> re.compile(r'"(.+)"."(.+)"').search('CAST("category"."quantity" AS int)') is not None
True
(You might also want to replace (.+)
with (.+?)
, in case your string has more than four double quotes. And though I'm not sure about the central dot character, perhaps you want an explicit \.
there? Then the pattern would become
r'"(.+?)"\."(.+?)"'
which doesn't match something like 'CAST("category"+"quantity" AS "int")'
, or at least returns the correct matched part (true, that's not valid SQL, but to give a quick idea.))