Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: DSLs in perl and python (Was sobering observation) Date: Fri, 18 Mar 2016 14:22:25 +0100 Organization: None Lines: 32 Message-ID: References: <7f139f92-3957-40e5-be75-ad19b9401617@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de R+GIQtSEc1UTgF85DfwxcweF+xyufWg917s/5w41P8Sg== 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; '"""': 0.05; 'mrab': 0.05; 'friday,': 0.07; 'thats': 0.07; 'question?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'subject:python': 0.14; '"x"': 0.16; '(there': 0.16; '2016': 0.16; 'describing': 0.16; 'r"""': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:Was': 0.16; 'wrote:': 0.16; 'char': 0.18; 'stick': 0.18; '>>>': 0.20; 'somewhere': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; "skip:' 10": 0.28; 'looks': 0.29; 'perl': 0.29; 'thanks!': 0.34; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'doing': 0.38; 'end': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'march': 0.64; 'series': 0.65; 'issued': 0.66; 'dsl': 0.84; 'utc+5:30,': 0.84; 'indicator': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd8a1a.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 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:105211 Rustom Mody wrote: > On Friday, March 18, 2016 at 4:17:06 AM UTC+5:30, MRAB wrote: >> Stick an "x" on the end of the regex: /something/x or s/old/new/x. > > Thanks! > > Is there somewhere a regexp 'introspection' API/capability available? > > ie if the re looks like > rexp = r""" > # DSL (instantiation) for describing NYSE symbology > ^ > (?P [A-Z]*) # The base scrip > (?P [.+-])? # Series type char > (?P [A-Z])? # Series > (?P [#])? # issued char indicator > $ # Thats all (there should be!) > """ > > I would like to know that the named-groups are > {scrip, serchar, series, issued} > without doing match/search etc Is that a Perl or a Python question? If the latter: >>> r = re.compile(rexp, re.VERBOSE) >>> r.groupindex {'serchar': 2, 'issuedc': 4, 'scrip': 1, 'series': 3}