Skip to content

Instantly share code, notes, and snippets.

@hekt
Created August 14, 2011 16:59
Show Gist options
  • Save hekt/1145069 to your computer and use it in GitHub Desktop.
Save hekt/1145069 to your computer and use it in GitHub Desktop.
RegEx for parsing CSS
(# comment )
(/\*(?:(?!\*/)[\s\S])*\*/)
(/\*(?:[^*]|\*[^/])*\*/)
(# @keyframes-rule )
(@(?:-webkit-|-moz-)?keyframes(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)+[a-zA-Z0-9_\-]+(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)*{(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)*(?:(?:from|to|[0-9]{1,3}%)(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)*{(?:[^{}"']|/\*(?:(?!\*/)[\s\S])*\*/|'[^']*'|"[^"]*")*}(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)*)+(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)*})
(# ruleset )
((?:[^{}"']|'[^']*'|"[^"]*")+(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)*{(?:[^{}"']|/\*(?:(?!\*/)[\s\S])*\*/|'[^']*'|"[^"]*")*})
(# block )
({(?:[^{}"']|/\*(?:(?!\*/)[\s\S])*\*/|'[^']*'|"[^"]*")*})
(# declaration )
([a-zA-Z\-]+(?:\s|/\*(?:(?!\*/)[\s\S])*\*/)*:(?:\s|/\*(?:(?!\*/)[\s\S])*\*/)*(?:"[^"]*"|'[^']'|[^:;{}])+;?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment