Skip to content

Instantly share code, notes, and snippets.

@jonschlinkert
Created November 16, 2012 20:14
Show Gist options
  • Save jonschlinkert/4090489 to your computer and use it in GitHub Desktop.
Save jonschlinkert/4090489 to your computer and use it in GitHub Desktop.
My commonly used regular expressions

##Find/Replace tag attributes

###everything between <a >

<div/?[a\s]*[^>]*>

###everything between

href="/?[a\s]*[^>]*?" 

###this is the replace for the last one

href="#" 

###Remove all @import's from css

@import "/?[a\s]*[^>]*?";

###Replace EVERYTHING after a certain expression

<tabTrigger/?[a\s]*[^]*$

###another example, where we want to replace "]]>" and everything that follows. "" escapes "]]>" so that it can be read.

\]]>/?[a\s]*[^]*$

###Replace ALL HTML tags, but not content

</?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)/?>

###everything in an href betweem the =" "

(?<=href=("|'))[^"']+(?=("|'))

###replace it with

#

###Delete all closing tags

</*?(.*?)>

###Delete all tags up to the first "

<*?(.*?)="

##CSS

###Delete all css properties

{ *?(.*?)}

###Find all that match

-webkit(.+?):(.+?);

###CSS, remove rules that begin with UNUSED (helps with refactoring)

UNUSED([^,}]+)\}|,\s?UNUSED([^{]+)|UNUSED([^{]+),\s?|UNUSED([^{]+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment