DSLs in perl and python (Was sobering observation)
Peter Otten
__peter__ at web.de
Fri Mar 18 09:22:25 EDT 2016
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<scrip> [A-Z]*) # The base scrip
> (?P<serchar> [.+-])? # Series type char
> (?P<series> [A-Z])? # Series
> (?P<issuedc> [#])? # 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}
More information about the Python-list
mailing list