Flash / Regular expressions class for Flash 5 / Flash MX |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RegExp class for Flash 5 / Flash MX |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I have been doing a lot of programming with JavaScript and PHP, and using regular expressions extensively. They are very handy in situations where one has to check for validity of user input, or some complex string manipulation such as URL-wrapping all Email addresses within the given plain text. All this and much more can be done with couple of lines when you use regular expressions. Please believe me, when I say that regular expressions may some day save hundreds of hours of coding, and will make your code more readable and efficient. Much of stuff is written by many authors, so I won't repeat them here. If you are interested in regular expressions, go to some online source. Here's a couple of them for start: http://www.webreference.com/js/column5/ 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. Anyway, the lack of RegExp support was reason why I decided to write a class to enable regular expressions in ActionScript. After a week of serious coding, the result is here. It is almost 100% compatible with JavaScript 1.2 standard, except for minor syntax issue: Flash ActionScript syntax does not allow to use forward slashes upon regular expression assignment. To be sincere, my ActionScript class is not the first one. To my surprise, the forerunner with publicising his code couple of days ahead was some guy Andy Black with his version of RegExp object. Since I wanted to come public with finished code and be as much close to JavaScript syntax as possible, I hesitated about it. However, applause to Andy, he didn't let me sleep on laurels. Let you be the judge which implementation to use. Flash MX 2004Flash 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 generalHere'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: DownloadsRegExp.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. License
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 pavils@mailbox.riga.lv 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 requestPlease 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
Frequently Asked Questions: Q:
I think your engine has a bug. Q:
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 Known bugs: - 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. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||