Flash / Regular expressions class for Flash 5 / Flash MX
RegExp class for Flash 5 / Flash MX
So, when I started to dig through Flash5 ActionScript, to my disappointment I found no RegExp object there. Asking Macromedia people about why this is so I've got response that the size of Flash player would be too large with this functionality. Well, that's too bad. I am not sure though if it's true. Pure code should not be more than 10Kb. Is that a lot? Maybe. People of Macromedia have great pressures when deciding which features make it to the player binary code, because the plugin file size is a scarce resource. When Flash MX and Flash 6 player was introduced, the RegExp engine still was not there. An now, when Flash MX 2004 with the new Flash 7 player is here, we still don't have this industry standard present. However, a new product, Macromedia Central, has a special player that has RegExp support built in. While that is a good sign, the penetration rate of this player is not expected to be very high in the public internet.
Flash MX 2004
Flash MX 2004 comes with completely upgraded OOP ActionScript syntax, making it more like Java. That requires a new enigne AS code, that is doomed to have some compatibilty difficulties, since the Flash ActionScript compiler has got smarter and does not let to use new string object methods that are added at runtime. I still am consulting with MM people how to overcome there compatibility issues. There are two or three classes somewhere in the air, that are made by eager coomunity memers. Those are based completely on the current Flash 5/MX code, wrapped in the new OOP syntax. There are several problems with these classes, and I don't feel like putting them here for distribution, as it would induce proliferation of non-standard code. So, I have put the developement of my version of MX 2004 code until I can get some cooperation from the Macromedia side.
Meanwhile, to answer all your requests for "at least any" support
for MX 2004, I provide one class for download. It is made by Joey
Lott, it is pure encapsulation of the original Flash 5/MX into the
new AS2 syntax. I am afraid I can not provide support, if some questions
arise, though send them to me and will sort that out.
Books about RegExp in Flash, or regular expressions in general
Here's an assortment of several books, that cover the use of this class in Flash application development, and also highly valuable book about regexes in general:
RegExp.as - Single class file
If you make some project with this class, and this project is available
online, please send me a link
so I can have a link to it on this page. I think it is important to make
Flash people more acquainted with the power of regular expressions.
This class is provided for flash community for free with a kind request to keep the copyright lines in AS file untouched. However, debugging and development of class takes much time limiting my opportunities to earn some income on other projects. To overcome this, I have set up an account with PayPal. Please, if you find my work valuable, especially if you use it in commercial projects, make a donation to email@example.com of amount you feel is right. Please provide your E-mail address upon payment submission so I can enlist you in my upgrade newslist. If you decide to extend the class, or to base your distributable projects by using this class, try to separate the extension code from the original, leaving the original class code unchanged. Also, make sure that the ECMAscript standard is met. Do not host this class on your site, but provide a link to this page instead, as I may put bug-fixed and updated versions here. Please inform me on your intentions to include this class in some other projects so we can decide which distribution framework is best.
A little request
Please keep reporting me how exactly do you use this class in your projects. Please, don't be lazy. I would be happy to compile a regex case studies from your reports.
Brief documentation and notes
I think your engine has a bug.
I have this code:
Looking for help on:
RegExp.multiline property - why the hack RegExp has this property, if
regular expression object already has it
- In case of ORed expressions with parens like "(abc)|(def)|(ghi)" when
testing on string "defghiabc" the $1..$9 and lastParen properties of RegExp
(and return array of exec()) contain different values from MSIE5.5 implementation.
For the sake of speed, this class walks through all the ORed sections
remembering parenthesized components, and jumps to the next OR section
once surpasses the best matching index so far. MSIE5.5 evaluates all sections
separately and remembers parenthesized component matches only from the
winner section, leaving all other empty.