template strings for matching?

Tino Wildenhain tino at wildenhain.de
Thu Oct 9 14:52:24 CEST 2008

Joe Strout wrote:
> Catching up on what's new in Python since I last used it a decade ago, 
> I've just been reading up on template strings.  These are pretty cool!  
> However, just as a template string has some advantages over % 
> substitution for building a string, it seems like it would have 
> advantages over manually constructing a regex for string matching.
> So... is there any way to use a template string for matching?  I 
> expected something like:
>  templ = Template("The $object in $location falls mainly in the $subloc.")
>  d = templ.match(s)
> and then d would either by None (if s doesn't match), or a dictionary 
> with values for 'object', 'location', and 'subloc'.
> But I couldn't find anything like that in the docs.  Am I overlooking 
> something?

Yeah, its a bit hard to spot:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20081009/adb69c78/attachment.bin>

More information about the Python-list mailing list