Thursday, December 12, 2013

A Quick Regular Expression (Regex) to Pull Colors From a CSS Stylesheet

This one's mostly for my quick personal reference. It wasn't hard by any means but figured someone else might find it useful.


I need to find all hex color codes in a style sheet so I can extract them.

I came up with a quick Regex (regular expression) to do this:


Essentially, it just looks for a pound symbol (#), followed by any amount of numbers 0-9 or letters a-f, followed by a semi-colon.

If you're interested to try it, you can view my example over at Regex Tester.

It's not the slickest but it got the job done quickly.

Happy coding!

No comments:

Post a Comment

Keep it classy, folks.