Skip to content

Instantly share code, notes, and snippets.

@jongacnik
Forked from hekt/regex_css
Created September 11, 2017 04: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 jongacnik/4ae091ddfddfab6850d615036be220fa to your computer and use it in GitHub Desktop.
Save jongacnik/4ae091ddfddfab6850d615036be220fa 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