Code: Alles auswählen
import re
txt = open("/path/to/foobar.css","r").read()
txt = re.sub("/\*.*?\*/(?s)", "", txt) # remove /* multi line */ comments
txt = re.sub("//.*?(?m)", "", txt) # remove // single line comments
regex = re.compile(
r"""
(?P<name>.*?)
\{
(?P<data>.*?)
\}""",
re.IGNORECASE | re.VERBOSE | re.UNICODE
)
for match in regex.finditer(txt):
css_data = match.group("data")
if not "color" in css_data:
continue
print("%s {" % match.group("name"))
for part in css_data.split(";"):
if "color" in part:
print("\t%s;" % part)
print("}")