Q:

In python extending the string. Template class for easy regular expressions

I like everything about python mostly thanks to its simplicity.  I feel regular expressions have taken me away from my love for python far too many times.  As such I wanted to extend the already existing string. Template class which lets me set variables in a string so that I can get values of an already existing string. 
My first attempt works pretty well but has a few drawbacks:
import re
from string import Template
class TemplateX(Template):
    def getvalues(self,Str):
        regex = r""
        skipnext = False
        for i in self.template:
            if skipnext == False:
                if i ! = "$":
                    regex += i
                else:
                    regex += r"(.+)"
                    skipnext = True
            else:
                skipnext = False
        values = re.search(regex,Str).groups()
        return values

temp = TemplateX("  Coords;     $x;$y;$z;\n")
newstring = temp.substitute(x="1",y="2",z="3")
print newstring

values = temp.getvalues(newstring)
print values

newstring prints as: "  Coords;     1;2;3;\n"
values prints as: ("1","2","3")
I am fine with losing some functionality of re for this simpler approach. 
My question is how can i add a little more functionality to getvalues to allow for variables in TemplateX to be more than 1 character (like the Template class and substitute allows).  i.e. so that this works:
temp = TemplateX("  Coords;     $xvar;$yvar;$zvar;\n")
newstring = temp.substitute(xvar="1",yvar="2",zvar="3")
print newstring

values = temp.getvalues(newstring)
print values

temp2 = TemplateX("  FindThese:    $gx = $gy - $gz")
values2 = temp2.getvalues("  FindThese:    $10000 = $10 - $5x")

A:

You're pretty much trying to turn a template into a regex reading that template, right?  That's not always doable, for example if you have a template "$x$y" and a string "abc", you can't know whether it's ("ab", "c"), ("abc", "") or some other case.  And it's not just the case with template variables sitting next to each other. 
So if you want to this kind of stuff, you have to know what's in the strings you feed to it.  That is – that there are some characters between the variables that don't occur in the variables themselves (i.e. variables are all digits and there are semicolons between them in the template).  If you're just parsing some input, you'd probably be safer if you just wrote your own regexes. 
That said, you can do something like this:
class TemplateX(Template):
    def getvalues(self,Str):
        """ Reads a string matching the template to find the original values. 

            >>> temp = TemplateX("Blah: $xx;$y;")
            >>> newsting = temp.substitute(xx="1",y="2")
            >>> temp.getvalues(newstring)
            ('1', '2')

        """
        regex = re.sub(self.pattern, "(.*)",  self.template)
        m = re.match(regex, Str)
        return m.groups()

It uses Template's own mechanism for finding the placeholders and replaces them with regex wildcards.  Then it runs the regex on the given string. 
You could also try to get the initial keyword arguments:
    def getvalues(self,Str):
        regex = re.sub(self.pattern, r"(?P<\2>.*)",  self.template)
        m = re.match(regex, Str)
        return m.groupdict()

And then choke it with:
temp = TemplateX("$a$a")
newstring = temp.substitute(a='a')
print temp.getvalues(newstring)

