In article <ef48ad50-da06-47a8-978a-47d6f4271...@d28g2000yqf.googlegroups.com> ru...@yahoo.com <ru...@yahoo.com> wrote (in part): [mass snippage] >What I mean is that I see regexes as being an extremely small, >highly restricted, domain specific language targeted specifically >at describing text patterns. Thus they do that job better than >than trying to describe patterns implicitly with Python code.
Indeed. Kernighan has often used / supported the idea of "little languages"; see: http://www.princeton.edu/~hos/frs122/precis/kernighan.htm In this case, regular expressions form a "little language" that is quite well suited to some lexical analysis problems. Since the language is (modulo various concerns) targeted at the "right level", as it were, it becomes easy (modulo various concerns :-) ) to express the desired algorithm precisely yet concisely. On the whole, this is a good thing. The trick lies in knowing when it *is* the right level, and how to use the language of REs. >On 06/03/2011 08:05 PM, Steven D'Aprano wrote: >> If regexes were more readable, as proposed by Wall, that would go >> a long way to reducing my suspicion of them. "Suspicion" seems like an odd term here. Still, it is true that something (whether it be use of re.VERBOSE, and whitespace-and-comments, or some New and Improved Syntax) could help. Dense and complex REs are quite powerful, but may also contain and hide programming mistakes. The ability to describe what is intended -- which may differ from what is written -- is useful. As an interesting aside, even without the re.VERBOSE flag, one can build complex, yet reasonably-understandable, REs in Python, by breaking them into individual parts and giving them appropriate names. (This is also possible in perl, although the perl syntax makes it less obvious, I think.) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html
-- http://mail.python.org/mailman/listinfo/python-list