Skip to content

Instantly share code, notes, and snippets.

@jedie
Created April 29, 2015 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedie/379c25305185183da0b8 to your computer and use it in GitHub Desktop.
Save jedie/379c25305185183da0b8 to your computer and use it in GitHub Desktop.
list all CSS lines with color values
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("}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment