|
The power of RegEx (Regular Expressions) |
|
|
|
|
Written by Edward Prevost
|
|
Tuesday, 04 December 2007 |
Over my career I have had some interesting discussions regarding the usage of regular expressions (RegEx), most of them have dealt primarily with the incredible power that RegEx places in the hands of a Software Engineer, recently I found myself in a brief discussion which challeneged me to defend the practical aspects of RegEx; mainly, is it practical?
The question itself arises from the presupposition that software languages need to inherintly have certain properties, amongst which should be found practicality. That is, the language should be realatively easy to: read, write, understand and troubleshoot. In general I find myself pulled more violently toward lanuages that offer robust solutions for these presuppositions, such as: C#, PHP, Coldfusion, Python and Actionscript. Now some may scoff at this list, but if given the time I could expound each of these languages so crisply handles a given issue of software architecture... which is another post all together...
RegEx, is it Practical? Yes. Emphatically yes. How kind of me to simply state my conclusion rather than seek to logically demonstrate RegEx's Practicality. Well her is a list, you decide for yourself:
- Found in some form in almost every language available
- NOT difficult to learn, contrary to popular belief
- Provides blazing-fast manipulation, validation and comparison
- POWERFUL, accomplishing tasks that would otherwise take hundreds of lines of code (if not thousands) to reproduce
Well, enough persuasion with words, allow me to truly demonstrate RegEx's power.... (please give credit if you utilize this code in ANY fashion)
COMPLETE REGEX EMAIL VALIDATION - Fully Standards Compliant Email Validating Regular Expression (© Covenant eDesign)^((([a-z]|[0-9]|!|[#]|$|%|&|'|\*|\+|\-|/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|[#]|$|%|&|'|\*|\+|\-|/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-) {0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|ax|az|ba|bb|bd| be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec| edu|ee|eg|eh|er|es|et|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir| is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv| mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd| se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za| zm|zw))|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$
|
|
Last Updated ( Tuesday, 04 December 2007 )
|