def transformString( self, instring ):
out = []<EOL>lastE = <NUM_LIT:0><EOL>self.keepTabs = True<EOL>try:<EOL><INDENT>for t,s,e in self.scanString( instring ):<EOL><INDENT>out.append( instring[lastE:s] )<EOL>if t:<EOL><INDENT>if isinstance(t,ParseResults):<EOL><INDENT>out += t.asList()<EOL><DEDENT>elif isinstance(t,list):<EOL><INDENT>out += t<EOL><DEDENT>else:<EOL><INDENT>out.append(t)<EOL><DEDENT><DEDENT>lastE = e<EOL><DEDENT>out.append(instring[lastE:])<EOL>out = [o for o in out if o]<EOL>return "<STR_LIT>".join(map(_ustr,_flatten(out)))<EOL><DEDENT>except ParseBaseException as exc:<EOL><INDENT>if ParserElement.verbose_stacktrace:<EOL><INDENT>raise<EOL><DEDENT>else:<EOL><INDENT>raise exc<EOL><DEDENT><DEDENT>
Extension to :class:`scanString`, to modify matching text with modified tokens that may
be returned from a parse action.  To use ``transformString``, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking ``transformString()`` on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action.  ``transformString()`` returns the resulting transformed string.

Example::

    wd = Word(alphas)
    wd.setParseAction(lambda toks: toks[0].title())

    print(wd.transformString("now is the winter of our discontent made glorious summer by this sun of york."))

prints::

    Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York.