Skip to content

Instantly share code, notes, and snippets.

@bhowe
Created April 28, 2016 18:26
Show Gist options
  • Select an option

  • Save bhowe/db9190be35a26ca1719684200e1b9f71 to your computer and use it in GitHub Desktop.

Select an option

Save bhowe/db9190be35a26ca1719684200e1b9f71 to your computer and use it in GitHub Desktop.
RegEx's that you can use to match @media rules are:
^\@media\s(.*?)\{$
^ = assert position at start of the string
\@ = matches the character @ literally
media = matches the characters media literally
\s = match any white space character [\r\n\t\f ]
.*? = matches any character (except newline)
{ = matches the character { literally
$ = assert position at end of the string
\@media\s(.*?)\{
\@ = matches the character @ literally
media = matches the characters media literally
\s = match any white space character [\r\n\t\f ]
.*? = matches any character (except newline)
{ = matches the character { literally
Also you can use the i to make the RegEx's case insensitive (i only ignores the case of [a-zA-Z])
Here are four possible ways of detecting @media rules using RegEx:
/^\@media\s(.*?)\{$/
/^\@media\s(.*?)\{$/i
/\@media\s(.*?)\{/
/\@media\s(.*?)\{/i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment