Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

ShowUsYour<Regex>

Irregular Expressions Regularly

compressing javascript code in perl

While sneaking around the web tonight looking at sites which have interesting dhtml controls or cool stylesheets, I came across this article:

    http://www.bazon.net/mishoo/articles.epl?art_id=209

I couldn't help but start pulling apart some of those regex's.  The one which strips whitespace at the beginning and end of lines is quite familiar:

    \n)\s+|\s+(?:$|\n))
   

This regex is basically saying:

   either anchor at ^ or \n and slurp all whitespace
or
   slurp all whitespace up until the $ or \n anchors

so, while the alternation is costly, overall the regex is very readable and maintainable.  The C-style comment regex on the other hand seems way too complicated compared to my C-style regex which can be found at RegexLib.com here:

    http://regexlib.com/REDetails.aspx?regexp_id=445

Overall though, it's not the regex whackiness that I wanted to highlight; it's the script.  This seems like a nice, lean way to reduce the byte size of js code files.

Sponsor
Published Tuesday, January 25, 2005 10:25 PM by digory
Filed under:

Comments

 

digory said:

HTML::Clean? Even comes with an Apache2 filter called Apache::Clean. Remember - every good idea probably has a CPAN implementation.
April 5, 2005 8:04 AM
Anonymous comments are disabled