Skip to content

Instantly share code, notes, and snippets.

@ryelle
Created January 26, 2014 20:41
Show Gist options
  • Select an option

  • Save ryelle/8639210 to your computer and use it in GitHub Desktop.

Select an option

Save ryelle/8639210 to your computer and use it in GitHub Desktop.
Regex for finding margins & padding in CSS. Ended up not terribly useful, but interesting?
(padding|margin)(-top|-left|-right|-bottom)?:(\s*(\d*(.\d*)?(em|rem|px|)|auto)){1,4}\s*(!important)?;
@laurensiusadi
Copy link

Here I am 7 years later finding this useful for refactoring a project with lots of these inline styles. I'm using the regex in VS Code search.

@BrunoFenzl
Copy link

Fantastic! Thank you so much! Worked perfectly

@kszalwinski-rbi
Copy link

Thanks for this, but it could be updated to match negative values like:

margin: -9px;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment