Fork me on GitHub

Useful Regex

A collection of useful regular expressions I use or I’ve used during my coding life. They are written using Perl notation.

CSS : find all the the last rules not terminating with a semi-colon and put one:
s/(\w|\d)(?!;)(\s*|\n)(})/$1;$2$3/g

CSS: find a specific class in your html files:
/class=(\"|\')(\w\s+)*(YourCssClassHere)(\s+\w)*(\"|\')/ OR better (using the boundaries)
/class=[\"\'][a-zA-Z_\s\-]*?\bYourCssClassHere\b[a-zA-Z_\s\-]*[\"\']/ OR (using the boundaries and including the non alphanumeric chars)
/class=[\"\'][^\"\']*?\bYourCssClassHere\b[^\"\']*[\"\']/

No comments yet.


Leave a comment

(required)

(required)