[Tutor] Regex comments

Michael Powe michael at trollope.org
Thu Sep 16 13:44:22 CEST 2010


On Thu, Sep 16, 2010 at 01:31:09PM +0200, Peter Otten wrote:
> Michael Powe wrote:
 
> > The re module includes the option to comment a regular expression with
> > the syntax (?#comment).  e.g.

> > 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'}

That's right, I forgot about the dictionary.  Thanks!

mp

-- 
Michael Powe		michael at trollope.org		Naugatuck CT USA
"No provision in our Constitution ought to be dearer to man than that
which protects the rights of conscience against the enterprises of the
civil authority." -- Thomas Jefferson to New London Methodists,
1809. ME 16:332
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20100916/037ea572/attachment.pgp>


More information about the Tutor mailing list