[Tutor] Regex comments
Peter Otten
__peter__ at web.de
Thu Sep 16 13:31:09 CEST 2010
Michael Powe wrote:
> The re module includes the option to comment a regular expression with
> the syntax (?#comment). e.g.
>
> p=r'(.*) (?P<grp>WT.dl)(?#parameter)=(?P<val>[^&]+)(?#value).*'
>
> Is there a mechanism for extracting these values from the match, in
> the way that group names are extracted?
>
> I don't see one.
You could write a regular expression to extract them ;)
> The point would be that in my processing of the match, I could
> implement the comments as identifiers for the matched value.
But that's what the names are for, e. g.:
>>> re.compile(r'(.*) (?P<parameter>WT.dl)=(?P<value>[^&]+).*').search(
" WTxdl=yadda&ignored").groupdict()
{'parameter': 'WTxdl', 'value': 'yadda'}
Or am I missing something?
Peter
More information about the Tutor
mailing list