Use searchinstead match. matchmatches the pattern only at the beginning of the line.
>>> color_regex_test1.search('color: #333;').group()
'#333'
BTW is #not particularly significant in regular expression. You do not need to put it inside [...]to fit it literally:
>>> color_regex_test1 = re.compile('#\w{3,6}')
>>> color_regex_test1.search('color: #333;').group()
'#333'
source
share