Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Michael Torrie Newsgroups: comp.lang.python Subject: Re: Regular expressions Date: Tue, 03 Nov 2015 19:04:23 -0700 Lines: 37 Message-ID: References: <662g3blobme52hfoududj27err185v2npm@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de f8irQnrTyMquyAUZjDQn7QQzP0gBILVftPE2YR/XddOA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'patterns': 0.04; 'resulting': 0.04; 'expressions': 0.07; 'finite': 0.09; 'grep': 0.09; 'methods,': 0.09; 'patterns,': 0.09; 'res': 0.09; 'unexpected': 0.09; 'python': 0.10; 'index': 0.13; 'explicitly': 0.15; 'languages,': 0.15; 'cleanly': 0.16; 'describing': 0.16; 'expressions,': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'maintainable': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'regex,': 0.16; 'subject:Regular': 0.16; 'subject:expressions': 0.16; 'terse': 0.16; 'why,': 0.16; 'wrote:': 0.16; 'string': 0.17; 'say,': 0.18; 'programmer': 0.18; 'input': 0.18; 'language': 0.19; 'c++,': 0.22; 'programming': 0.22; 'code.': 0.23; 'bit': 0.23; 'ease': 0.23; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'header:User-Agent:1': 0.26; 'earlier': 0.27; 'supported': 0.27; 'not.': 0.27; 'regular': 0.29; 'etc).': 0.29; 'certainly': 0.30; 'query': 0.30; 'relative': 0.30; 'operations': 0.31; 'probably': 0.31; 'maybe': 0.33; 'class': 0.33; 'accessible': 0.33; 'message-id:@gmail.com': 0.34; 'know.': 0.34; 'except': 0.34; 'clear': 0.35; 'library.': 0.35; 'requiring': 0.35; 'but': 0.36; 'there': 0.36; '(and': 0.36; 'mode': 0.36; 'projects.': 0.36; "wasn't": 0.36; 'to:addr:python- list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:org': 0.37; 'beyond': 0.37; 'things': 0.38; 'itself': 0.38; 'means': 0.39; "didn't": 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'skip:u 10': 0.61; 'default': 0.61; 'charset:windows-1252': 0.62; 'needing': 0.63; 'more': 0.63; 'more.': 0.63; 'developed': 0.66; 'python-list': 0.66; 'fact,': 0.67; 'college': 0.67; 'detecting': 0.84; 'pain': 0.84; 'maybe,': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98198 On 11/03/2015 05:33 PM, rurpy--- via Python-list wrote: > I consider regexs more fundemental. One need not even be a programmer > to use them: consider grep, sed, a zillion editors, database query > languages, etc. Grep can use regular expressions (and I do so with it regularly), but it's default mode is certainly not regular expressions, and it is still very powerful. I've never used regular expressions in a database query language; until this moment I didn't know any supported such things in their queries. Good to know. How you would index for regular expressions in queries I don't know. > When there is a mini-language explicitly developed for describing > string patterns, why, except is very simple cases, would one not > take advantage of it? Mainly because the programming language itself often can do it just as cleanly and just as fast (slicing, string methods, etc). I certainly programmed for many years without needing regular expressions in my small projects. In fact, REs are a bit of a pain to use in, say, C or C++, requiring a library. With Python they are much more readily accessible so I use them much more. But honestly it wasn't until college when I learned about finite state automata that I really grasped what regular expressions were and how to use them. > Beyond trivial operations a regex, although > terse (overly perhaps), is still likely to be more understandable > more maintainable than bunch of ad-hoc code. And the relative ease > of expressing complex patterns means one is more likely to create > more specific patterns, resulting in detecting unexpected input > earlier than with ad-hoc code. Maybe, maybe not. Using Python string class methods is probably more clear when such methods are sufficient.