I am working on a simple CSS parser in Python. Right now I want to extact all values from this string: "1px solid rgb(255, 255, 255)"
. Right now my pattern (which is not working) is: "\S+[^rgb]+"
. When I use it with string "1px solid rgb(255, 255, 255)"
, I get following:
...
>>> re.findall("\S+[^rgb]+", string)
("1px solid", "rgb(255, 255, 255)")
And I want it to be
("1px", "solid", "rgb(255, 255, 255)")
P.S.
Also, is there a better way for parsing CSS declaration? Currently my pattern is "[\s]?(\S+)[\s]?:[\s]?(.+)[\s]?;"
. Parsing "color: red;"
gives me:
("color", "red")